How to Create a Dataset with JSONB Values
The JSONB data type is utilized in databases to efficiently store JSON data in a binary format. It is commonly employed in databases like PostgreSQL that support this data type. JSONB is a flexible option for efficiently storing and querying semi-structured or hierarchical data, often represented in JSON format, within a relational database system. The subsequent steps outline the procedure for creating a dataset with JSONB value:
- Begin by creating a table in PostgreSQL.
CREATE TABLE JsonBTable (id serial PRIMARY KEY,jsonbNameAge jsonb;)
- Insert JSONB data into the table.
INSERT INTO JsonBTable (jsonbNameAge) VALUES ('{"name": "John", "age": 32}');
INSERT INTO JsonBTable VALUES (2,'{"name": "Josh", "age": 29}');
-
Connect the PostgreSQL and create the dataset.
-
By following these steps, you will be able to create a report with JSONB columns, as demonstrated in the provided example.
-
To select a specific field from the JSONB table, switch to code mode in the query designer.
Use the following syntax to select a specific field from the JSONB table
SELECT <<-jsonb_column::jsonb->>‘field_name’ AS extracted_field
- Add a table and incorporate the dataset into the table. Preview the report to view the results.