I have a table in my database, which contains character varying column and this column has json. I need to write a query, which will somehow parse this json into separate columns.
I found json_each function here but I can't understand how to work with it.
What Is PostgreSQL? PostgreSQL is a Relational Database Management System (RDBMS) developed by the PostgreSQL Global Development Group. It has been in use for over 20 years and supports both SQL and JSON for relational and non-relational queries in order to provide flexibility and SQL compliance.
To query JSON data, you can use standard T-SQL. If you must create a query or report on JSON data, you can easily convert JSON data to rows and columns by calling the OPENJSON rowset function. For more information, see Convert JSON Data to Rows and Columns with OPENJSON (SQL Server).
JSONB supports indexing the JSON data, and is very efficient at parsing and querying the JSON data. In most cases, when you work with JSON in PostgreSQL, you should be using JSONB.
I figured it out, guys
if I have a table books
I can easily write a query
SELECT id, data::json->'name' as name FROM books;
And it will result in
I can also try to get non-existent column
SELECT id, data::json->'non_existant' as non_existant FROM books;
And it this case I will get empty result
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With