pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Bogdan Stepanenko <bscheshir@gmail.com>
Cc: Postgres Bug <pgsql-bugs@postgresql.org>
Cc: Bruce Momjian <bruce@momjian.us>
Subject: Re: defaut value '1' in smallint column is a string value '1' in pgsql >= 9.5
Date: Wed, 24 Jan 2018 18:58:55 -0500
Message-ID: <15194.1516838335@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwYxwWQ8z7_nwXUmaXt87EhnLSkYa1VWKtHxNv0NsAczxw@mail.gmail.com>
References: <CAM3H=w4JZ_aqt8kFX4GebbckNG2quSeBA+JFXEuFYju2cnwX7w@mail.gmail.com>
	<CAKFQuwYxwWQ8z7_nwXUmaXt87EhnLSkYa1VWKtHxNv0NsAczxw@mail.gmail.com>

"David G. Johnston" <david.g.johnston@gmail.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@sss.pgh.pa.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




view thread (4+ messages)

Message-ID: <15194.1516838335@sss.pgh.pa.us>
Permalink:  ../15194.1516838335@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/15194.1516838335@sss.pgh.pa.us

 · 

reply

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, david.g.johnston@gmail.com, bscheshir@gmail.com, bruce@momjian.us
  Subject: Re: defaut value '1' in smallint column is a string value '1' in pgsql >= 9.5
  In-Reply-To: <15194.1516838335@sss.pgh.pa.us>
  References: <CAM3H=w4JZ_aqt8kFX4GebbckNG2quSeBA+JFXEuFYju2cnwX7w@mail.gmail.com> <CAKFQuwYxwWQ8z7_nwXUmaXt87EhnLSkYa1VWKtHxNv0NsAczxw@mail.gmail.com> <15194.1516838335@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