Re: Turn a json column into a table

From: Thomas Kellerer <shammat(at)gmx(dot)net>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Turn a json column into a table
Date: 2022-02-15 06:27:29
Message-ID: 054f5de0-6160-bee4-9ed7-ec2f7d0aba23@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Shaozhong SHI 2022-02-15 11:08:07 Operator % and its meaning and use
Previous Message Shaozhong SHI 2022-02-15 06:23:59 Turn a json column into a table