Nag
Nag

Reputation: 129

How to create table to store json object data in PostgreSQL database?

I am new to PostgreSQL database(9.5.0), I need to store my json data in PostgreSQL database, so that I need to create a table for it, how can I create a table for it to store my json object on clicking of submit button from my front-end, so that it will be stored in created database table and my sample josn object is as follows(having key/value pairs, contains files also), Please help me.

{"key1":"value1","key2":"value2","key3":"value3","key4_file_name":"Test.txt"}

Upvotes: 7

Views: 11004

Answers (1)

Patrick
Patrick

Reputation: 32364

PostgreSQL has the json and jsonb (b for binary) data types. You can use these in your table definitions just like any other data type. If you plan to merely store the json data then the json data type is best. If, on the other hand, you plan to do a lot of analysis with the json data inside the PG server, then the jsonb data type is best.

Upvotes: 9

Related Questions