Languages
[Edit]
EN

PostgreSQL - Insert JSON type value to the table

0 points
Created by:
Tehya-Blanchard
474

In this article, we would like to show you how to insert JSON type value to the table in PostgreSQL.

Quick solution:

INSERT INTO "table_name" ("column_name")
VALUES
    ('{"key1": value1, "key2": value2, "key3": value3}'),
    ('{"key4": value4, "key5": value5, "keyN": valueN}');

 

Practical example

To show how to insert JSON type values to the table, we will use the objects table created in the previous article:

PostgreSQL - example data used to insert JSON type values
PostgreSQL - example data used to insert JSON type values

Example

In this example, we will insert into the objects table three new JSON values.

Query:

INSERT INTO "objects" ("json")
VALUES
    ('{"height": 100, "width": 100, "color": "red"}'),
    ('{"height": 200, "width": 200, "color": "green"}'),
    ('{"height": 300, "width": 300, "color": "blue"}');

Result:

PostgreSQL - INSERT INTO JSON type value - result
PostgreSQL - INSERT INTO JSON type value - result

Related posts

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

PostgreSQL - problems

PostgreSQL - Insert JSON type value to the table
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join