JSON as core type in PostgreSQL 9.2

It looks like PostgreSQL 9.2 will get a JSON core type. Additionally, there will be functions to produce JSON data from database queries:

  • query_to_json()
  • array_to_json()
  • row_to_json()

Here is a simple example that uses the new query_to_json function:

SELECT query_to_json('select user_name as username, role_name as role from USER',false);

This query will produce JSON data:

[{"username":"testuser","role":"user"},{"username":"johndoe","role":"admin"}]

This could be very useful for web applications that use a lot of JSON data to communicate between the frontend and backend.

Short URL for this post: http://wp.me/p4nxik-OC
This entry was posted in Java Persistence and tagged , . Bookmark the permalink.

Leave a Reply