PostgreSQL 9.2 introduced the json field type. Why and when should I use it? What benefits does it have over a text field?
I thought there were new query options available, however I haven't seen any. Am I missing something?
|
PostgreSQL 9.2 introduced the I thought there were new query options available, however I haven't seen any. Am I missing something? |
||||
|
|
|
The benefit of the new feature is two-fold. Columns of type I quote Andrew Dunstan on the pgsql-hackers list:
I used that quote before under this related question on SO. |
|||||||
|
|
Basically I see three use cases here:
The first one can be done directly from PostgreSQL with no addons needed. You should be able to do something like:
This can then be used to create nested arrays etc. in your output and avoid a lot of messy parsing problems on the app side. the second is passing complex data into the db for processing. Currently there are no built-in functions to facilitate this, but with addons like pl/v8js, you can program your database in Javascript and use json as an exchange format. This can allow the creation of richer interfaces inside your database. Note that since you can index function outputs, you can use this to create indexes of aspects of JSON to be stored in your db. The third is one area we plan to use it in LedgerSMB. The idea is that we might want to allow system integrators to store very simple information along with customer accounts. This could then be packed in a JSON field that would be stored. This would not be able to be directly queried by the main apps, but if folks wanted to add this using pl/v8js this could be done for individual businesses using the software. |
|||
|
|