Re: cant get what I want from array_to_json (simple)

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Michael Moore <michaeljmoore(at)gmail(dot)com>
Cc: postgres list <pgsql-sql(at)postgresql(dot)org>
Subject: Re: cant get what I want from array_to_json (simple)
Date: 2015-12-16 21:42:13
Message-ID: CAKFQuwaH7RS=v7rWu8XCNJwoC6Y4nrqo9aqiYtoFjR-Ze2ivXA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, Dec 16, 2015 at 2:23 PM, Michael Moore <michaeljmoore(at)gmail(dot)com>
wrote:

> CREATE TYPE key_value_pair AS
> (key text,
> value text);
>
> DO $$declare
> arr qsn_app.key_value_pair[];
> pcolumn_values_i json;
> begin
> arr[0] := ('this','that');
> arr[1] := ('another','one');
> pcolumn_values_i := array_to_json( arr );
> RAISE NOTICE '#1 %', pcolumn_values_i;
> end$$;
>
> the 'NOTICE' shows:
> NOTICE: #1 [{"key":"this","value":"that"},{"key":"another","value":"one"}]
> what I want to see is:
> NOTICE: #1 {"this":"that","another":"one"}
>
>
>
​The "json(_build)_object​()" functions seems like they better match your
need.

http://www.postgresql.org/docs/current/static/functions-json.html

David J.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message britt_mcclafferty 2015-12-16 22:06:54 Help with complicated query (total SQL newb!)
Previous Message Michael Moore 2015-12-16 21:23:59 cant get what I want from array_to_json (simple)