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

From: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
To:
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Extract elements from JSON array and return them as concatenated string
Date: 2018-03-14 22:27:05
Message-ID: CAADeyWgtcTgMnbhyemTxqxew+YT5OeYJkc2AYFnQSGGPuwBN4g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thank you -

On Wed, Mar 14, 2018 at 8:41 PM, Ivan E. Panchenko <
i(dot)panchenko(at)postgrespro(dot)ru> 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='play'
> 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='play'
words(> order by played desc limit 5
words(> ) y;
string_agg
----------------
А Н Т Щ П
(1 row)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Paquier 2018-03-14 23:32:38 Re: wiki Disk Usage, table size: ERROR: could not open relation with OID 0
Previous Message Stephen Frost 2018-03-14 22:17:01 Re: PgBackrest questions