How to load JSON data in PostgreSQL with the COPY command
You have a JSON dataset that you want to upload to a PostgreSQL table containing properly formatted rows and columns… How do you do it?
All the main sources like my own blog and others tell you to load the JSON in a dedicated temporary table containing a unique JSON
column, then parse it and load into the target table. However there could be another way, avoiding the temp table!
How to load JSON data in PostgreSQL®?
PostgreSQL® offers two types of data types to handle JSON data, JSON
and JSONB
. This doc showcases how to load JSON data into a column.
How to tabulate a JSON to a record in PostgreSQL®
PostgreSQL® offers two types of data types to handle JSON data, JSON
and JSONB
, and provides two different ways to tabulate a JSON to a record:
How to tabulate a JSON to a recordset in PostgreSQL®
PostgreSQL® offers two types of data types to handle JSON data, JSON
and JSONB
, and provides two different ways to tabulate a JSON to a recordset:
How to edit a JSON object in PostgreSQL®?
PostgreSQL® offers two types of data types to handle JSON data, JSON
and JSONB
, you can use the jsonb_set
function to remove the null values for JSONB columns.
How to remove an item from a JSON array in PostgreSQL®?
PostgreSQL® offers two types of data types to handle JSON data, JSON
and JSONB
, you can use the -
operator to remove an item from an array.
How to remove fields from a JSON document in PostgreSQL®?
PostgreSQL® offers two types of data types to handle JSON data, JSON
and JSONB
, and provides two different ways to remove fields from a JSON document:
How to remove nulls JSON object in PostgreSQL®?
PostgreSQL® offers two types of data types to handle JSON data, JSON
and JSONB
, you can use the json_strip_nulls
(jsonb_strip_nulls
for JSONB) function to remove the null values.
How to concatenate two JSON documents in PostgreSQL®?
PostgreSQL® offers two types of data types to handle JSON data, JSON
and JSONB
, you can use the opearator ||
to concatenate two JSON objects.
How to create a JSON object from array of key/value pairs in PostgreSQL®?
PostgreSQL® offers two types of data types to handle JSON data, JSON
and JSONB
, you can use the function json_object
(jsonb_object
for JSONB
) to create a JSON object from an array of key/value pairs.