BUG #3037: strange behave of CHECK constraint

Lists: pgsql-bugs
From: "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #3037: strange behave of CHECK constraint
Date: 2007-02-20 16:31:30
Message-ID: 200702201631.l1KGVU48054533@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 3037
Logged by: Pavel Stehule
Email address: pavel(dot)stehule(at)hotmail(dot)com
PostgreSQL version: 8.3
Operating system: Linux
Description: strange behave of CHECK constraint
Details:

check constraint is incorect for operator SIMILAR

root=# create table products(
barcode char(13) NOT NULL
check (barcode NOT similar to '%[^0-9]%')
);

root=# insert into products values('22');
ERROR: new row for relation "products" violates check constraint
"products_barcode_check"
root=# insert into products values('aa');
ERROR: new row for relation "products" violates check constraint
"products_barcode_check"

root=# select '22' NOT similar to '%[^0-9]%';
?column?
----------
t
(1 dka)


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #3037: strange behave of CHECK constraint
Date: 2007-02-23 04:54:08
Message-ID: 11475.1172206448@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

"Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com> writes:
> root=# create table products(
> barcode char(13) NOT NULL
> check (barcode NOT similar to '%[^0-9]%')
> );

> root=# insert into products values('22');
> ERROR: new row for relation "products" violates check constraint
> "products_barcode_check"

> root=# select '22' NOT similar to '%[^0-9]%';
> ?column?
> ----------
> t

That isn't a counterexample, because you forgot about the trailing
spaces, which can match [^0-9].

regression=# select '22' NOT similar to '%[^0-9]%';
?column?
----------
t
(1 row)

regression=# select '22'::char(13) NOT similar to '%[^0-9]%';
?column?
----------
f
(1 row)

regards, tom lane


From: "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com>
To: tgl(at)sss(dot)pgh(dot)pa(dot)us
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #3037: strange behave of CHECK constraint
Date: 2007-02-23 06:43:37
Message-ID: BAY114-F3882FD09D541A289EBC55BF98E0@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

>"Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com> writes:
> > root=# create table products(
> > barcode char(13) NOT NULL
> > check (barcode NOT similar to '%[^0-9]%')
> > );
>
> > root=# insert into products values('22');
> > ERROR: new row for relation "products" violates check constraint
> > "products_barcode_check"
>
> > root=# select '22' NOT similar to '%[^0-9]%';
> > ?column?
> > ----------
> > t
>
>That isn't a counterexample, because you forgot about the trailing
>spaces, which can match [^0-9].
>
>regression=# select '22' NOT similar to '%[^0-9]%';
> ?column?
>----------
> t
>(1 row)
>
>regression=# select '22'::char(13) NOT similar to '%[^0-9]%';
> ?column?
>----------
> f
>(1 row)
>
>

I see it now. Thank You. It's one trick from Joe Celko and I too late
understand it.

Nice day
Pavel Stehule

_________________________________________________________________
Emotikony a pozadi programu MSN Messenger ozivi vasi konverzaci.
http://messenger.msn.cz/