Re: PATCH: Implement value_to_json for single-datum conversion

Поиск
Список
Период
Сортировка
От Craig Ringer
Тема Re: PATCH: Implement value_to_json for single-datum conversion
Дата
Msg-id 50289BD2.1050607@ringerc.id.au
обсуждение исходный текст
Ответ на Re: PATCH: Implement value_to_json for single-datum conversion  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On 08/13/2012 01:55 PM, Tom Lane wrote:
> Actually, given the above, what did you need value_to_json(text) for at
> all?  Wouldn't value_to_json(anyelement) have covered it?

Usability. Without the version accepting text an explicit cast to text 
is required to disambiguate a literal argument like 
value_to_json('something') .

> But yeah, the general approach to suppressing complaints from that
> opr_sanity test is to make more C entry points.  The point of it,
> in some sense, is that if you want to make an assumption that two
> types are binary-equivalent then it's better to have that assumption
> in C code than embedded in the pg_proc entries.  The cases that we
> let pass via the "expected" outputs are only ones where binary
> equivalence seems pretty well assured, like text vs varchar.

Thanks. I appreciate the explanation, and sorry for the newbie error.


On the JSON stuff, I can see it's not as simple as adding a simple 
escape function. For my needs during the 9.2 timeframe I'll bundle up an 
extension with the functionality I need and deal with the need to port 
to whatever 9.3 includes. Hopefully a "json_value" or "javascript_value" 
or similar can be introduced for 9.3, given comments like:
  http://archives.postgresql.org/pgsql-hackers/2012-05/msg00030.php
http://archives.postgresql.org/pgsql-hackers/2012-05/msg00065.php

.. expressing not only the need for json scalars, but the fact that 
they're already commonplace in pretty much everything else.

Given this:
  http://archives.postgresql.org/pgsql-hackers/2012-05/msg00040.php

it does seem that `json' should be a whole document not a fragment, but 
IMO a way to work with individual JSON values is going to be *necessary* 
to get the most out of the json support - and to stop people who use 
JSON in the real world complaining that Pg's JSON support is broken 
because it follows the standard not real-world practice.

Personally the lack of json scalars has prevented me from using JSON 
support in two different places already, though it's proving very useful 
in many others.

--
Craig Ringer



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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: PATCH: Implement value_to_json for single-datum conversion
Следующее
От: Heikki Linnakangas
Дата:
Сообщение: Re: default_isolation_level='serializable' crashes on Windows