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: pgsql-bugs@postgresql.org
Cc: dgrelaud@ideolys.com
Subject: Re: Re: BUG #11103: to_json() does not convert correctly DOMAINs type since 9.3.5 (int expected instead of string) ?
Date: Thu, 07 Aug 2014 16:59:20 -0400
Message-ID: <20389.1407445160@sss.pgh.pa.us> (raw)
In-Reply-To: <1406881632112-5813509.post@n5.nabble.com>
References: <20140731152456.2708.35688@wrigleys.postgresql.org>
	<CAB7nPqSznbjfmuMzoHpwm4cP8M1rOSE+CtCuWOP9owAp5GS4vQ@mail.gmail.com>
	<1406881632112-5813509.post@n5.nabble.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

David G Johnston <david.g.johnston@gmail.com> writes:
> Michael Paquier wrote
>> On Fri, Aug 1, 2014 at 12:24 AM,  <dgrelaud@> wrote:
>>> With 9.3.5,  it returns a JSON string : '2' (with quotes)
>>> With 9.3.4,  it returns a JSON int : 2 (without quotes)

> Since the unsigned_int4 is a domain now, in head, it would appear without
> the quotes.  Before the patch, in 9.3.4, it also appeared without the
> quotes.  After the patch, in 9.3.5, it now has quotes so the patch has
> already changed user-visible behavior which is the reason Tom didn't
> back-patch the part that pertained to domains.

Hm ... actually the intent of that was to *not* cause a behavior change in
pre-9.4.  But it looks like things are more complicated than I thought.

A domain inherits the typcategory of its base type, which means that in
the old coding that relied on typcategory to decide what to do, domains
*were* treated the same as their base types, in some cases anyway.
Specifically it looks like the old behavior was:

* If there was a cast function to json, you got the behavior of that
cast function.  The cast had to be from exactly the given type (ie,
in this case, the domain not its base type).

* If the type was JSON (or JSONB, though that's not relevant to pre-9.4),
you got the JSON-appropriate behavior.  Again, it had to be exactly JSON
and not a domain over same.

* Otherwise you got classification according to typcategory, which *would*
effectively look through domains.  Specifically, domains over boolean
and domains over numeric types would be converted like their base types.

So I was thinking about not changing the first two cases and failed to
realize the side-effects for the last case.

I'm inclined to think that the best thing to do is add the getBaseType
call in the older branches too.  That will restore the previous behavior
for domains over booleans and numerics.  It will change the behavior
for the other two cases, which would affect domains over json and hstore
in particular; but arguably that's a bug fix.  The old behavior was
just plain inconsistent, because it effectively looked through domains
over some types and not domains over others.

Thoughts, objections?

			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



view thread (5+ messages)

Message-ID: <20389.1407445160@sss.pgh.pa.us>
Permalink:  ../20389.1407445160@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/20389.1407445160@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, dgrelaud@ideolys.com
  Subject: Re: BUG #11103: to_json() does not convert correctly DOMAINs type since 9.3.5 (int expected instead of string) ?
  In-Reply-To: <20389.1407445160@sss.pgh.pa.us>
  References: <20140731152456.2708.35688@wrigleys.postgresql.org> <CAB7nPqSznbjfmuMzoHpwm4cP8M1rOSE+CtCuWOP9owAp5GS4vQ@mail.gmail.com> <1406881632112-5813509.post@n5.nabble.com> <20389.1407445160@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