json_populate_recordset and nested object, how to solve? - Mailing list pgsql-general

From Raphael Bauduin
Subject json_populate_recordset and nested object, how to solve?
Date
Msg-id CAONrwUFRsVqpzGMg7+ga8PEJy+nKCZ1FWxaBU8WMZuaJn8AsqA@mail.gmail.com
Whole thread Raw
Responses Re: json_populate_recordset and nested object, how to solve?  (Raphael Bauduin <rblists@gmail.com>)
List pgsql-general
Hi,

here is an example of a problem I encounter with json_populate_recordset because it does not support nested object. Actually, I would prefer that it ignores nested object rather than raise an error, as it fails on a key I don't even want to use!

Here's the query:

select e.timestamp::date, e.user_id, rs.similarity from
  (select * from events where type='suggestion' and timestamp<'2014-04-04' and timestamp>'2014-04-03') e
   CROSS JOIN LATERAL
  json_populate_recordset(null::suggestion, event->'products') rs
order by e.user_id;


event->'products' is an array of json objects, one of this keys (stock) being an array of json objects. I can absolutely ignore that key in this query, but I don't see how. The suggestion type does not have a stock key, so it would be absent of the result anyway.

So, how would you get event->'products' without the stock keys, just to be able to call json_populate_recordset?

Thanks.

Raph

PS: this might be seen as a followup to a previous mail thread: http://www.postgresql.org/message-id/CAONrwUGMQthsut_F8X4CBGQDuKa5=A+AtmxSXb2FdOXh5PD3Qg@mail.gmail.com
but I don't see how to apply that suggestion here.

pgsql-general by date:

Previous
From: Armand Turpel
Date:
Subject: hstore - jsonb
Next
From: Tjibbe
Date:
Subject: create temp view from function inside plpgsql function.