Search Postgresql Archives

Re: Extract elements from JSON array and return them as concatenated string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thank you -

On Wed, Mar 14, 2018 at 8:41 PM, Ivan E. Panchenko <i.panchenko@xxxxxxxxxxxxxx> wrote:

    
Yes, here x is the alias for the record, not for the json field. So you need to write the query like 

select string_agg(x->>'letter', ' ')
from (
   select jsonb_array_elements(tiles) x
   from words_moves
   where gid=656 and action=""
   order by played desc limit 5
) y;



This has worked perfectly:

words=> select string_agg(x->>'letter', ' ') 
words-> from (
words(>    select jsonb_array_elements(tiles) x 
words(>    from words_moves
words(>    where gid=656 and action="">
words(>    order by played desc limit 5
words(> ) y;
   string_agg   
----------------
 А Н Т Щ П
(1 row)
 


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux