Re: defaut value '1' in smallint column is a string value '1' in pgsql >= 9.5

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Bogdan Stepanenko <bscheshir(at)gmail(dot)com>, Postgres Bug <pgsql-bugs(at)postgresql(dot)org>, Bruce Momjian <bruce(at)momjian(dot)us>
Subject: Re: defaut value '1' in smallint column is a string value '1' in pgsql >= 9.5
Date: 2018-01-24 23:58:55
Message-ID: 15194.1516838335@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> 9.3: <1::smallint>
> 9.6: <'1'::smallint>

Oh, right, this was an intentional change awhile back. The form without
the quotes is actually an incorrect representation of the internal state:
what that produces, if you feed it back into the parser, is an int4
constant with a run-time conversion to int2. The runtime conversion will
get const-folded during planning, resulting in more or less the same
behavior; but it's nonetheless a different expression tree from the second
form, which is an int2 constant, full stop.

(digs...) It was changed in this 9.5-era commit:

commit 542320c2bd0b3796a8a9a4617cdb23fbad473390
Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Date: Mon Mar 30 14:59:49 2015 -0400

Be more careful about printing constants in ruleutils.c.

The previous coding in get_const_expr() tried to avoid quoting integer,
float, and numeric literals if at all possible. While that looks nice,
it means that dumped expressions might re-parse to something that's
semantically equivalent but not the exact same parsetree; for example
a FLOAT8 constant would re-parse as a NUMERIC constant with a cast to
FLOAT8. Though the result would be the same after constant-folding,
this is problematic in certain contexts. In particular, Jeff Davis
pointed out that this could cause unexpected failures in ALTER INHERIT
operations because of child tables having not-exactly-equivalent CHECK
expressions. Therefore, favor correctness over legibility and dump
such constants in quotes except in the limited cases where they'll
be interpreted as the same type even without any casting.

This results in assorted small changes in the regression test outputs,
and will affect display of user-defined views and rules similarly.
The odds of that causing problems in the field seem non-negligible;
given the lack of previous complaints, it seems best not to change
this in the back branches.

I don't see anything about this commit in the 9.5 release notes, which
perhaps is an oversight.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2018-01-25 10:18:13 BUG #15030: wrong address when connect
Previous Message David G. Johnston 2018-01-24 23:32:19 Re: defaut value '1' in smallint column is a string value '1' in pgsql >= 9.5