Re: [HACKERS] WIP json generation enhancements

2012-12-05 Thread David E. Wheeler
On Nov 26, 2012, at 11:12 AM, Peter Eisentraut wrote: > Although my intuition would be [], the existing concatenation-like > aggregates return null for no input rows, so this probably ought to be > consistent with those. This annoys me at times, but I wrap such calls in COALESCE() and forget abo

Re: [HACKERS] WIP json generation enhancements

2012-11-30 Thread Andrew Dunstan
On 11/27/2012 02:38 PM, Andrew Dunstan wrote: On 11/26/2012 12:31 PM, Robert Haas wrote: On Mon, Nov 26, 2012 at 11:43 AM, Andrew Dunstan wrote: I don't understand why you would want to create such a cast. If the cast doesn't exist it will do exactly what it does now, i.e. use the type's ou

Re: [HACKERS] WIP json generation enhancements

2012-11-27 Thread Andrew Dunstan
On 11/26/2012 12:31 PM, Robert Haas wrote: On Mon, Nov 26, 2012 at 11:43 AM, Andrew Dunstan wrote: I don't understand why you would want to create such a cast. If the cast doesn't exist it will do exactly what it does now, i.e. use the type's output function and then json quote and escape it,

Re: [HACKERS] WIP json generation enhancements

2012-11-26 Thread Robert Haas
On Mon, Nov 26, 2012 at 3:05 PM, Tom Lane wrote: > The analogy to other aggregates is probably a better thing to argue > from. On the other hand, I don't know anyone outside the SQL standards > committee who thinks it's actually a good idea that SUM() across no rows > returns null rather than zer

Re: [HACKERS] WIP json generation enhancements : strange IS NULL behaviour

2012-11-26 Thread Tom Lane
Hannu Krosing writes: > On 11/26/2012 09:05 PM, Tom Lane wrote: >> The analogy to other aggregates is probably a better thing to argue >> from. On the other hand, I don't know anyone outside the SQL standards >> committee who thinks it's actually a good idea that SUM() across no rows >> returns n

Re: [HACKERS] WIP json generation enhancements : strange IS NULL behaviour

2012-11-26 Thread Hannu Krosing
On 11/26/2012 09:05 PM, Tom Lane wrote: Hannu Krosing writes: In some previous mail Tom Lane claimed that by SQL standard either an array of all NULLs or a record with all fields NULLs (I don't remember which) is also considered NULL. If this is true, then an empty array - which can be said to

Re: [HACKERS] WIP json generation enhancements

2012-11-26 Thread Tom Lane
Hannu Krosing writes: > In some previous mail Tom Lane claimed that by SQL standard > either an array of all NULLs or a record with all fields NULLs (I > don't remember which) is also considered NULL. If this is true, > then an empty array - which can be said to consist of nothing > but NULLs - sh

Re: [HACKERS] WIP json generation enhancements: fk-tree-to-json()

2012-11-26 Thread Hannu Krosing
On 11/22/2012 11:54 AM, Dimitri Fontaine wrote: Andrew Dunstan writes: Here is a WIP patch for enhancements to json generation. First, there is the much_requested json_agg, which will aggregate rows directly to json. So the following will now work: select json_agg(my_table) from mytable;

Re: [HACKERS] WIP json generation enhancements

2012-11-26 Thread Andrew Dunstan
On 11/26/2012 02:46 PM, Hannu Krosing wrote: On 11/26/2012 08:12 PM, Peter Eisentraut wrote: On 11/21/12 3:16 PM, Andrew Dunstan wrote: One open question regarding this feature is whether this should return NULL or '[]' for 0 rows. Currently it returns NULL but I could be convinced to return '

Re: [HACKERS] WIP json generation enhancements

2012-11-26 Thread Hannu Krosing
On 11/26/2012 08:12 PM, Peter Eisentraut wrote: On 11/21/12 3:16 PM, Andrew Dunstan wrote: One open question regarding this feature is whether this should return NULL or '[]' for 0 rows. Currently it returns NULL but I could be convinced to return '[]', and the change would be very small. Altho

Re: [HACKERS] WIP json generation enhancements

2012-11-26 Thread Peter Eisentraut
On 11/21/12 3:16 PM, Andrew Dunstan wrote: > One open question regarding this feature is whether this should return > NULL or '[]' for 0 rows. Currently it returns NULL but I could be > convinced to return '[]', and the change would be very small. Although my intuition would be [], the existing co

Re: [HACKERS] WIP json generation enhancements

2012-11-26 Thread Merlin Moncure
On Thu, Nov 22, 2012 at 4:54 AM, Dimitri Fontaine wrote: > Andrew Dunstan writes: >> Here is a WIP patch for enhancements to json generation. >> >> First, there is the much_requested json_agg, which will aggregate rows >> directly to json. So the following will now work: >> >> select json_agg

Re: [HACKERS] WIP json generation enhancements

2012-11-26 Thread Robert Haas
On Mon, Nov 26, 2012 at 11:43 AM, Andrew Dunstan wrote: > I don't understand why you would want to create such a cast. If the cast > doesn't exist it will do exactly what it does now, i.e. use the type's > output function and then json quote and escape it, which in the case of > citext is the Righ

Re: [HACKERS] WIP json generation enhancements

2012-11-26 Thread Andrew Dunstan
On 11/26/2012 10:55 AM, Robert Haas wrote: On Wed, Nov 21, 2012 at 3:16 PM, Andrew Dunstan wrote: Non-builtin types are now searched for a cast to json, and if it exists it is used instead of the type's text representation. I didn't add a special type to look for a cast to, as was discussed be

Re: [HACKERS] WIP json generation enhancements

2012-11-26 Thread Robert Haas
On Wed, Nov 21, 2012 at 3:16 PM, Andrew Dunstan wrote: > Non-builtin types are now searched for a cast to json, and if it exists it > is used instead of the type's text representation. I didn't add a special > type to look for a cast to, as was discussed before, as it seemed a bit > funky and unne

Re: [HACKERS] WIP json generation enhancements

2012-11-22 Thread Andrew Dunstan
On 11/22/2012 05:54 AM, Dimitri Fontaine wrote: Andrew Dunstan writes: Here is a WIP patch for enhancements to json generation. First, there is the much_requested json_agg, which will aggregate rows directly to json. So the following will now work: select json_agg(my_table) from mytable

Re: [HACKERS] WIP json generation enhancements

2012-11-22 Thread Dimitri Fontaine
Andrew Dunstan writes: > Here is a WIP patch for enhancements to json generation. > > First, there is the much_requested json_agg, which will aggregate rows > directly to json. So the following will now work: > > select json_agg(my_table) from mytable; > select json_agg(q) from () q; Awes

Re: [HACKERS] WIP json generation enhancements

2012-11-21 Thread Andrew Dunstan
On 11/21/2012 03:16 PM, Andrew Dunstan wrote: Here is a WIP patch for enhancements to json generation. First, there is the much_requested json_agg, which will aggregate rows directly to json. So the following will now work: select json_agg(my_table) from mytable; select json_agg(q) f

[HACKERS] WIP json generation enhancements

2012-11-21 Thread Andrew Dunstan
Here is a WIP patch for enhancements to json generation. First, there is the much_requested json_agg, which will aggregate rows directly to json. So the following will now work: select json_agg(my_table) from mytable; select json_agg(q) from () q; One open question regarding this feat