Home > Archive > PostgreSQL Bugs > May 2005 > CHECK constraint (true) causes dumps with parse errors









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author CHECK constraint (true) causes dumps with parse errors
Szûcs Gábor

2005-05-20, 3:24 am

Dear Gurus,

Version: 7.3.3, 7.4.8

I don't know for sure, but something like this happened when dumping our
server from 7.3 to 7.4. Actually, it seems to be a problem in 7.4 (maybe
also in 7.3, but unlikely -- see below, "our original way").

# create table foo (bar int, constraint foobar check (true or bar=1));
CREATE TABLE
# \d foo
Table "public.foo"
Column | Type | Modifiers
--------+---------+-----------
bar | integer |
Check constraints:
"foobar" CHECK (true OR bar = 1)

# drop table foo;
DROP TABLE
# create table foo (bar int, constraint foobar check (true));
CREATE TABLE
# \d foo
Table "public.foo"
Column | Type | Modifiers
--------+---------+-----------
bar | integer |
Check constraints:
"foobar" CHECK ()

Yours,
--
G.

---------------- our original way we found the problem:
-- original create command:
CREATE TABLE foo (
bar int,
CONSTRAINT foobar CHECK (true or bar=1)
);

-- 7.3 dump:
CREATE TABLE foo (
bar int,
CONSTRAINT foobar CHECK (true)
);

-- fed to 7.4, then \d
....
Check constraints:
"foobar" CHECK ()
-- note the empty parentheses!

-- mirroring the database caused:
ERROR: syntax error at or near ")" at character xxx

-- recreated table (actually, readded constraint) to 7.4, then \d
....
Check constraints:
"foobar" CHECK (true OR bar=1)


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Neil Conway

2005-05-20, 3:24 am

Szűcs Gábor wrote:
> # create table foo (bar int, constraint foobar check (true));
> CREATE TABLE
> # \d foo
> Table "public.foo"
> Column | Type | Modifiers
> --------+---------+-----------
> bar | integer |
> Check constraints:
> "foobar" CHECK ()


Yeah, I can repro this with current REL7_4_STABLE sources, but it looks
fixed in HEAD and REL8_0_STABLE.

-Neil

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Tom Lane

2005-05-20, 11:24 am

Neil Conway <neilc@samurai.com> writes:
> Szűcs Gábor wrote:
[color=darkred]
> Yeah, I can repro this with current REL7_4_STABLE sources, but it looks
> fixed in HEAD and REL8_0_STABLE.


I think the reason is that 7.4 applies make_ands_implicit before storing
the constraint, while 8.0 and up don't. I'm inclined to think it's not
worth trying to fix in the back branches.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Gábor SZÛCS

2005-05-21, 3:23 am

I agree it's not worth the effort, just found it "interesting" (duh)
and hastily sent a bugreport before checking upstream.

[off]
Another interesting story was 7.3 silently discarding unneeded
typecasts: create a view with a field ('a' || 'b')::varchar. The same
definition worked in 7.3 and 7.4 (both created a varchar field), but
7.3 dropped the unneeded typecast, and when dumping from 7.3 to 7.4
all these fields became text. I think 7.3 was simply "too smart for
our dumb problems" :)
[/off]

On 5/20/05, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Neil Conway <neilc@samurai.com> writes:
>
>
> I think the reason is that 7.4 applies make_ands_implicit before storing
> the constraint, while 8.0 and up don't. I'm inclined to think it's not
> worth trying to fix in the back branches.
>
> regards, tom lane
>



--
G.

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com