From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jeff Davis <pgsql@j-davis.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: pg_get_constraintdef() doesn't always give an equal constraint
Date: Mon, 23 Mar 2015 19:32:33 -0400
Message-ID: <19820.1427153553@sss.pgh.pa.us> (raw)
In-Reply-To: <CAMp0ubcxvbnPevHz7LkTkRVDGvCgs+JTHCUn1pYMT-CK9cdJPg@mail.gmail.com>
References: <CAMp0ubcxvbnPevHz7LkTkRVDGvCgs+JTHCUn1pYMT-CK9cdJPg@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Jeff Davis <pgsql@j-davis.com> writes:
> 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)
What's evidently happening here is that ruleutils.c thinks it can dump a
float8 constant using the syntax "10.1::double precision", but the parser
will interpret that as a numeric constant with a separate cast step.
I don't see any simple way around that except to dump using the syntax
'10.1'::double precision
which is ugly as sin, but perhaps we have no choice. A longer-term
solution might be to get the parser to interpret
10.1::double precision
as a float8 literal to start with, but that seems like it could have
unexpected side-effects? Not sure.
OTOH, you could argue that existing dump files already have the
unquoted-literal syntax so it behooves us to try to get the parser
to read them as they were meant.
A larger issue is that I have a nasty feeling that this isn't the
only place where ruleutils.c output might be read in a way that's
functionally equivalent to the original, but not the exact same
parsetree.
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, pgsql@j-davis.com
Subject: Re: pg_get_constraintdef() doesn't always give an equal constraint
In-Reply-To: <19820.1427153553@sss.pgh.pa.us>
References: <CAMp0ubcxvbnPevHz7LkTkRVDGvCgs+JTHCUn1pYMT-CK9cdJPg@mail.gmail.com> <19820.1427153553@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox