Re: pg_get_constraintdef() doesn't always give an equal constraint

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeff Davis <pgsql(at)j-davis(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: pg_get_constraintdef() doesn't always give an equal constraint
Date: 2015-03-28 19:08:16
Message-ID: 14244.1427569696@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Jeff Davis <pgsql(at)j-davis(dot)com> writes:
> On Mon, Mar 23, 2015 at 7:32 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> I don't see any simple way around that except to dump using the syntax
>> '10.1'::double precision

> There is a similar problem related to NUMERIC:
> '1'::numeric is dumped as
> 1::numeric
> which introduces a cast as well. There's also a problem with negative
> constants, because it introduces parenthesis instead of single quotes:
> '-1'::numeric
> is dumped as
> (-1)::numeric

Yeah. In general, this code was trying to produce something nice-looking
and semantically equivalent, but not necessarily something that would
re-parse as the exact same Const node.

> This bug is pretty old and nobody has complained about it before.
> Let's just figure out a good unambiguous representation of float and
> numeric literals, and then backport it. Anyone who cares enough to fix
> this issue can upgrade to the latest point release on the old version,
> and then dump/reload.

> For numeric, I think appending ".0" (if it's an integral value) is the
> easiest, prettiest, and least-surprising.

... and wrong, because that would affect the dscale. I don't think we
want this code editorializing on the printed format in any case.

> For floats, we can either
> use the single-quotes and type annotation, or we can come up with
> something new like appending an "f" to the value.

I cannot see back-porting anything as invasive as changing the lexer.

Basically, I think we have to change ruleutils so that it quotes anything
that wouldn't be seen as a simple integer or numeric constant by the
lexer+grammar.

The attached patch does this; the regression test changes illustrate
what's going to happen to the output if we do this.

Looking at the changes, I'm not 100% convinced we want to back-patch.
As you say, nobody's complained of this problem before, and I'm worried
that people will see the output changes as a bigger deal than the issue
we're trying to fix.

Thoughts?

regards, tom lane

(PS: I've not checked contrib or pl tests, so this patch may be incomplete
as far as expected-output changes go.)

Attachment Content-Type Size
fix-ruleutils-const-dumping.patch text/x-diff 23.2 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2015-03-28 19:32:27 Re: pg_get_constraintdef() doesn't always give an equal constraint
Previous Message and7ey 2015-03-28 12:07:42 BUG #12913: Installation fails: "database cluster initialisation failed"