Re: JSON row_to_json_array

From: Tjibbe R <tjibbe(at)rijpma(dot)org>
To:
Cc: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: JSON row_to_json_array
Date: 2013-09-23 08:26:03
Message-ID: BLU0-SMTP88643100CD56672B3F447DD2D0@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Yes it would be a simple array, but it costs a lot of coding. Because every
item in the array need to be inserted in the function to_json().

Example:

DECLARE
_arr json[];
FOR row in SELECT * FROM persons LOOP
_arr := array_append (_arr, ARRAY(to_json(row.id),
to_json(row.birthdate), to_json (row.active_bool),to_json(row.level));
END LOOP;
RETURN to_json(_arr);

On 23 September 2013 08:42, Luca Ferrari <fluca1978(at)infinito(dot)it> wrote:

> On Sat, Sep 21, 2013 at 10:26 PM, Tjibbe R <tjibbe(at)rijpma(dot)org> wrote:
> > Hello,
> >
> > Why isn't there a row_to_json_array(record) funtion?
> >
>
> I'm not a json expert, but it could be the output would not be a json
> structure (after all, it would be a simple array)?
>
> Luca
>

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Luca Ferrari 2013-09-23 12:09:44 Re: JSON row_to_json_array
Previous Message Luca Ferrari 2013-09-23 06:42:42 Re: JSON row_to_json_array