Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"}
like image 849
Nag Avatar asked Jan 18 '16 08:01

Nag


1 Answers

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.

like image 121
Patrick Avatar answered Sep 28 '22 16:09

Patrick