pg_get_constraintdef() doesn't always give an equal constraint - Mailing list pgsql-bugs

From Jeff Davis
Subject pg_get_constraintdef() doesn't always give an equal constraint
Date
Msg-id CAMp0ubcxvbnPevHz7LkTkRVDGvCgs+JTHCUn1pYMT-CK9cdJPg@mail.gmail.com
Whole thread Raw
Responses Re: pg_get_constraintdef() doesn't always give an equal constraint  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
create table pt(a int, b int, c float8 check (c < '10.1'));
create table ct(a int, b int, c float8);
select pg_get_constraintdef(oid) from pg_constraint where conname='pt_c_check';
         pg_get_constraintdef
--------------------------------------
 CHECK ((c < 10.1::double precision))
(1 row)

-- copy constraint to "ct" using syntax given above
alter table ct add constraint pt_c_check CHECK ((c < 10.1::double precision));
select pg_get_constraintdef(oid) from pg_constraint where conname='pt_c_check';
          pg_get_constraintdef
----------------------------------------
 CHECK ((c < 10.1::double precision))
 CHECK ((c < (10.1)::double precision))
(2 rows)

-- notice extra parenthesis above

-- now, we can't attach "ct" as an inheritance child of "pt"
alter table ct inherit pt;
ERROR:  child table "ct" has different definition for check constraint
"pt_c_check"

Also, the pg_dump output is different for pt and ct.

Strangely, the "\d" output is the same, so I tried using
pg_get_constraintdef with pretty-printing mode, which works fine. But
that's contrary to the docs, which say:

"The pretty-printed format is more readable, but the default format is
more likely to be interpreted the same way by future versions of
PostgreSQL; avoid using pretty-printed output for dump purposes."

Regards,
     Jeff Davis

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #12885: The result of casting a double to an integer depends on the database version
Next
From: Tom Lane
Date:
Subject: Re: pg_get_constraintdef() doesn't always give an equal constraint