pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Kellerer <shammat@gmx.net>
To: pgsql-general@lists.postgresql.org
Subject: Re: Turn a json column into a table
Date: Tue, 15 Feb 2022 07:27:29 +0100
Message-ID: <054f5de0-6160-bee4-9ed7-ec2f7d0aba23@gmx.net> (raw)
In-Reply-To: <CA+i5Jwa8bLKBWPYTrn0dsAKKFR9m1L1eFtj_vaCwBWqa4ibUZg@mail.gmail.com>
References: <CA+i5Jwa8bLKBWPYTrn0dsAKKFR9m1L1eFtj_vaCwBWqa4ibUZg@mail.gmail.com>


Shaozhong SHI schrieb am 15.02.2022 um 07:23:
> There is a JSON column in a table.  It contains key value pairs, just
> like a dictionary.  What is the best way to turn this column into a
> data table?

jsonb_each() is one option:

  select j.*
  from the_table t
    cross join jsonb_each(t.the_column) as j(key, value);


If the column uses the json type (rather than the recommended jsonb) you can
need to use json_each() instead.






view thread (2+ messages)

Message-ID: <054f5de0-6160-bee4-9ed7-ec2f7d0aba23@gmx.net>
Permalink:  ../054f5de0-6160-bee4-9ed7-ec2f7d0aba23@gmx.net/
Also on:    postgresql.org/message-id/054f5de0-6160-bee4-9ed7-ec2f7d0aba23@gmx.net

 · 

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-general@postgresql.org
  Cc: shammat@gmx.net
  Subject: Re: Turn a json column into a table
  In-Reply-To: <054f5de0-6160-bee4-9ed7-ec2f7d0aba23@gmx.net>
  References: <CA+i5Jwa8bLKBWPYTrn0dsAKKFR9m1L1eFtj_vaCwBWqa4ibUZg@mail.gmail.com> <054f5de0-6160-bee4-9ed7-ec2f7d0aba23@gmx.net>

* 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