Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XFUmY-0001Zr-UN for pgsql-bugs@arkaria.postgresql.org; Thu, 07 Aug 2014 20:59:31 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XFUmY-00065H-Es for pgsql-bugs@arkaria.postgresql.org; Thu, 07 Aug 2014 20:59:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XFUmX-00065A-Hj for pgsql-bugs@postgresql.org; Thu, 07 Aug 2014 20:59:29 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XFUmU-0005ca-Bk for pgsql-bugs@postgresql.org; Thu, 07 Aug 2014 20:59:28 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id s77KxKTZ020390; Thu, 7 Aug 2014 16:59:20 -0400 From: Tom Lane To: David G Johnston cc: pgsql-bugs@postgresql.org, 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) ? In-reply-to: <1406881632112-5813509.post@n5.nabble.com> References: <20140731152456.2708.35688@wrigleys.postgresql.org> <1406881632112-5813509.post@n5.nabble.com> Comments: In-reply-to David G Johnston message dated "Fri, 01 Aug 2014 01:27:12 -0700" Date: Thu, 07 Aug 2014 16:59:20 -0400 Message-ID: <20389.1407445160@sss.pgh.pa.us> X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org David G Johnston writes: > Michael Paquier wrote >> On Fri, Aug 1, 2014 at 12:24 AM, 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