Nikolay and Michael discuss JSON, options for storing it in Postgres, JSON functions available, JSONB indexing, popularity and advantages of PostgreSQL, configuring toast value threshold in Postgres, and performance penalties for medium-sized data.
JSON B is the recommended choice for storing JSON in Postgres due to its binary format, indexing support, and more efficient storage.
Careful consideration should be given to the use case and individual requirements when using JSON in Postgres, as it can lead to challenges in joining columns, lack of statistics, and potential data quality issues.
Deep dives
Storing JSON in Postgres and the options available
The podcast episode discusses the different options for storing JSON in Postgres, including arrays, H store, and JSON B. Arrays have been supported in Postgres for a long time and can store various types of data. H store, which is a key-value format, appeared in 2004 and provides flexibility. However, both arrays and H store break the first normal form. JSON B, implemented in 2014, is the recommended choice due to its binary format, indexing support, and more efficient storage.
Pros and cons of using JSON in Postgres
Using JSON in Postgres offers flexibility and convenience for developers. However, it is essential to be cautious about certain aspects. For instance, important data should not be stored solely in JSON but rather in regular columns for better control, constraints, and data quality. Updating and reading data in JSON can be more expensive, especially when it exceeds the toast threshold of 2 kilobytes. Furthermore, joining on JSON columns can be challenging, and there are no statistics available for internal JSON data. Careful consideration should be given to the use case and individual requirements.
History and development of JSON support in Postgres
JSON support in Postgres has evolved over time. JSON was included in Postgres in 2012, followed by JSON B in 2014, which added indexing capabilities. The introduction of JSON B made Postgres more popular and helped bridge the gap between relational and non-relational worlds. Postgres also offers functions and manipulation capabilities for JSON. The podcast episode highlights ongoing developments, such as support for SQL/JSON standard and improvements on updating toasted JSON values. It is recommended to stay informed about new features and optimizations in JSON support in Postgres.
Nikolay and Michael discuss JSON — our options for storing it in Postgres, whether or when we should, as well as a brief intro and some tips for JSON functions available.