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"}
1 Answer 1
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.
4 Comments
json data in PG implies that the document in text format has to be parsed before any operations take place on it, which is very inefficient compared to jsonb which does not require such preprocessing. If the JSON document is only stored in PG and not processed, I would only use json data only if the client application requires the JSON document in text format.
create table documents (id integer primary key, content jsonb)