pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: pgsql-bugs@lists.postgresql.org
To: david@daily-harvest.com
Subject: Re: BUG #15242: JSON functions not recognizing JSON
Date: Fri, 15 Jun 2018 01:20:02 +0100
Message-ID: <87a7rwsy9z.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <152899864499.24805.18088125700685635313@wrigleys.postgresql.org>
References: <152899864499.24805.18088125700685635313@wrigleys.postgresql.org>

>>>>> "PG" == PG Bug reporting form <noreply@postgresql.org> writes:

 PG> I get this error: SQL Error [22023]: ERROR: cannot deconstruct an
 PG> array as an object

 PG> when running the statement below because the JSON_EACH function
 PG> doesn't recognize the JSON.

It recognizes the json just fine, and so it can tell that it's an array
rather than the expected object. You were looking for
json_array_elements rather than (or prior to) json_each if you want to
enumerate the objects:

-- to get one row per object:

select json_array_length(txt::json), a.value
  from sample_text, json_array_elements(txt::json) as a;

-- to get one row per object key:

select json_array_length(txt::json), a.value, a.ord, e.key, e.value
  from sample_text,
       json_array_elements(txt::json) with ordinality as a(value,ord),
       json_each(a.value) as e;

-- 
Andrew (irc:RhodiumToad)




view thread (3+ messages)

Message-ID: <87a7rwsy9z.fsf@news-spur.riddles.org.uk>
Permalink:  ../87a7rwsy9z.fsf@news-spur.riddles.org.uk/
Also on:    postgresql.org/message-id/87a7rwsy9z.fsf@news-spur.riddles.org.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: andrew@tao11.riddles.org.uk, david@daily-harvest.com
  Subject: Re: BUG #15242: JSON functions not recognizing JSON
  In-Reply-To: <87a7rwsy9z.fsf@news-spur.riddles.org.uk>
  References: <152899864499.24805.18088125700685635313@wrigleys.postgresql.org> <87a7rwsy9z.fsf@news-spur.riddles.org.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox