Re: Re: BUG #11103: to_json() does not convert correctly DOMAINs type since 9.3.5 (int expected instead of string) ?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Re: BUG #11103: to_json() does not convert correctly DOMAINs type since 9.3.5 (int expected instead of string) ?
Дата
Msg-id 20389.1407445160@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: BUG #11103: to_json() does not convert correctly DOMAINs type since 9.3.5 (int expected instead of string) ?  (David G Johnston <david.g.johnston@gmail.com>)
Список pgsql-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

В списке pgsql-bugs по дате отправления:

Предыдущее
От: kuon@goyman.com
Дата:
Сообщение: BUG #11129: Centos 7 official contrib package is missing uuid-ossp
Следующее
От: Tom Lane
Дата:
Сообщение: Re: BUG #11109: No Toast compression on JSON, JSONB columns