Solution Review: JSON Data Type

See a detailed analysis of the solution to the "JSON Data Type" challenge.

In the challenge, you were asked to perform three tasks. Here, we’re going to discuss the solution to these three tasks.

Task 1

You were asked to create a cars table and insert data into it.

Solution

The DDL for creating the table and inserting records in the table is given below. You can check the data using the SELECT query given in the following playground. Click the “Run” button in the following widget to see the output of the code.

Press + to interact
/********************************************************/
/***** Write the queries for creating a table *****/
/***** and inserting the data into the table *****/
/********************************************************/
CREATE TABLE cars (
car_id serial unique,
car_info jsonb
);
INSERT INTO cars
VALUES (1, '{ "brand": "ferrari", "model": "testarosa" }'),
(2, '{ "brand": "aston martin", "model": "db2" }'),
(3, '{ "brand": "bentley", "model": "mulsanne" }'),
(4, '{ "brand": "ford", "model": "T" }');
SELECT * FROM cars;
/********************************************************/

Explanation

The explanation for task one of the challenge is given below: ...

Get hands-on with 1400+ tech skills courses.