Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparison of JSON and User-Defined types in Postgres 9.3

I wonder why there is so much fuss about JSON support in Postgres 9.3. What are advantages of JSON over User-defined types (UDTs)? What are pitfalls in using UDTs? Is access to tables with UDTs inefficient? Is ALTER TYPE ADD attribute slow? How are UDTs physically stored by Postgres?

Please, explain and give links to additional information.

like image 968
rlib Avatar asked Aug 07 '13 11:08

rlib


People also ask

What is JSON datatype in PostgreSQL?

JSON data types are for storing JSON (JavaScript Object Notation) data, as specified in RFC 7159. Such data can also be stored as text , but the JSON data types have the advantage of enforcing that each stored value is valid according to the JSON rules.

Should I use JSON in Postgres?

The comprehensive JSON support in PostgreSQL is one of its best-loved features. Many people – particularly those with a stronger background in Javascript programming than in relational databases – use it extensively.

Is Jsonb faster than JSON?

Because JSONB stores data in a binary format, queries process significantly faster. Storing data in binary form allows Postgres to access a particular JSON key-value pair without reading the entire JSON record. The reduced disk load speeds up overall performance. Support for indexing.

What is difference between JSON and Jsonb?

The key difference between them is that JSON stores data in a raw format and JSONB stores data in a custom binary format.


1 Answers

  • I think JSON is much more flexible than User-defined types, you can add whatever optional attributes you want, you can nest them, you can put them into lists;
  • JSON is very readable format;
  • JSON is standard object notation in many languages (Javascript, Python) so you can read data from table and use it;
  • You don't have to create new type anytime when you want to process data, you can create JSON, process it, then just forget about it;
like image 75
Roman Pekar Avatar answered Sep 30 '22 18:09

Roman Pekar