regular expression limit

Started by Ron Petersonover 19 years ago4 messagesgeneral
Jump to latest
#1Ron Peterson
ron.peterson@yellowbank.com

I believe there's been a change in PostgreSQL's regular expression
handling w/ 8.2.

CREATE TABLE testb (
name
TEXT
-- CHECK( name ~ '^[a-f0-9]{1,256}$' )
CHECK( name ~ '^[a-f0-9]{1,255}$' )
);

If I swap the two check statements above, I can no longer insert data.
The operation errors out with:

"invalid regular expression: invalid repetition count(s)"

I'd like the following domain statement to work. It used to work in
8.1.4, but not now. Can I do this in 8.2?

CREATE DOMAIN
__hex_string_8192
AS TEXT
CHECK ( VALUE ~ '^[a-f0-9]{1,8192}$' );

TIA.

--
Ron Peterson
https://www.yellowbank.com/

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Ron Peterson (#1)
Re: regular expression limit

Ron Peterson <ron.peterson@yellowbank.com> writes:

I believe there's been a change in PostgreSQL's regular expression
handling w/ 8.2.

Compared to what? A repeat count of 256 has been an error at least
since 7.4, and is documented as such:

: The numbers m and n within a bound are unsigned decimal integers with
: permissible values from 0 to 255 inclusive.

I'd like the following domain statement to work. It used to work in
8.1.4, but not now.

Sorry, I don't believe 8.1 took it either. Consider separating your
concerns, eg

CHECK( length(VALUE) <= 8192 AND VALUE ~ '^[a-f0-9]+$' )

regards, tom lane

#3Ron Peterson
ron.peterson@yellowbank.com
In reply to: Tom Lane (#2)
Re: regular expression limit

On Mon, Jan 01, 2007 at 11:30:00PM -0500, Tom Lane wrote:

Ron Peterson <ron.peterson@yellowbank.com> writes:

I believe there's been a change in PostgreSQL's regular expression
handling w/ 8.2.

Compared to what? A repeat count of 256 has been an error at least
since 7.4, and is documented as such:

: The numbers m and n within a bound are unsigned decimal integers with
: permissible values from 0 to 255 inclusive.

I'd like the following domain statement to work. It used to work in
8.1.4, but not now.

Sorry, I don't believe 8.1 took it either.

Hmm, my test table fails in 8.1.4 also, but my actual use case works in
8.1.4 but not 8.2.

CREATE DOMAIN
__hex_string_8192
AS TEXT
CHECK ( VALUE ~ '^[a-f0-9]{1,8192}$' );

CREATE TYPE __rsa_keys AS (
n
__hex_string_8192,
e
__hex_string_8192,
d
__hex_string_8192
);

CREATE OR REPLACE FUNCTION
y_pkcs_generate_rsa_keys(rd TEXT, sl INTEGER, mb INTEGER)
RETURNS
__rsa_keys
AS
'y_pkcs.so', 'y_pkcs_generate_rsa_keys'
LANGUAGE
C
STRICT IMMUTABLE;

When I call y_pkcs_generate_rsa_keys in 8.1.4 it works. When I call
this function in 8.2 it fails with the regular expression limit error.

I'll just revise my constraint as you suggested.

Consider separating your concerns, eg

CHECK( length(VALUE) <= 8192 AND VALUE ~ '^[a-f0-9]+$' )

That works for me. Thanks.

--
Ron Peterson
https://www.yellowbank.com/

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Ron Peterson (#3)
Re: regular expression limit

Ron Peterson <ron.peterson@yellowbank.com> writes:

Sorry, I don't believe 8.1 took it either.

Hmm, my test table fails in 8.1.4 also, but my actual use case works in
8.1.4 but not 8.2.

You haven't shown us exactly what that C function is doing, but my
interpretation of that is that 8.1 failed to check the domain
constraints at all, while 8.2 does it correctly.

regards, tom lane