Waiting for 9.4 – Add json_array_elements_text function.

On 29th of January, Andrew Dunstan committed patch:

Add json_array_elements_text function.
 
This was a notable omission from the json functions added in 9.3 and
there have been numerous complaints about its absence.
 
Laurence Rowe.

Yet another JSON support function. This time just one, and, looks rather simple. When you have JSON array, you can extract each value as text:

$ SELECT * FROM json_array_elements_text('["postgresql", "depesz", "universe"]'::json);
   VALUE    
------------
 postgresql
 depesz
 universe
(3 ROWS)

If any of the elements are non scalar – it just shows json representation:

$ SELECT * FROM json_array_elements_text('["postgresql", "depesz", "universe", [1,2,3], {"a":1, "b":2}]'::json);
     VALUE      
----------------
 postgresql
 depesz
 universe
 [1,2,3]
 {"a":1, "b":2}
(5 ROWS)

Simple, but it makes me happy, as it shows that we have general interest in JSON support. Cool.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.