PostgreSQL Database Quiz Questions

Course Name:PostgreSQL
Chapter Name:Chapter 5 - DDL (Data Definition Language)
Lesson Content Link:JSON Data Type
Current Quiz Count:30
Progress
0%
Q1
True / False

PostgreSQL allows storing JSON data directly in its tables.

Q2
True / False

The JSON data type in PostgreSQL automatically validates JSON syntax on insertion.

Q3
True / False

PostgreSQL can only store JSON data as text strings.

Q4
True / False

PostgreSQL’s JSONB type is more efficient for indexing and querying compared to the JSON type.

Q5
True / False

You can use the ->> operator to extract an element from a JSON array in PostgreSQL.

Q6
True / False

PostgreSQL provides functions to transform JSON data into PostgreSQL rows and vice versa.

Q7
True / False

In PostgreSQL, indexing a JSONB column with a GIN index allows for efficient search of nested keys and values.

Q8
True / False

PostgreSQL’s JSONB type preserves the original formatting and ordering of JSON data.

Q9
True / False

You can use the jsonb_set function in PostgreSQL to update a value in a JSONB column.

Q10
True / False

PostgreSQL's JSONB type is always preferred over JSON for all types of operations because it is universally more efficient.

Q11
Single Choice

Which MySQL data type should you use to store JSON data?

Q12
Single Choice

What will happen if you try to insert invalid JSON data into a MySQL JSON column?

Q13
Single Choice

Which MySQL function is used to validate whether a string is in valid JSON format?

Q14
Single Choice

What will be the result of the following query?

SQL Code
SELECT JSON_EXTRACT('{"name": "John", "age": 30}', '$.name');
Q15
Single Choice

How can you modify the value of a key in a JSON column in MySQL?

SQL Code
UPDATE employees SET details = JSON_SET(details, '$.salary', 50000) WHERE id = 1;
Q16
Single Choice

What does the following query return?

SQL Code
SELECT JSON_UNQUOTE(JSON_EXTRACT('{"city": "New York"}', '$.city'));
Q17
Single Choice

Which MySQL function would you use to merge two JSON documents into a single JSON document?

SQL Code
SELECT JSON_MERGE_PRESERVE('{"a": 1}', '{"b": 2}');
Q18
Single Choice

What will be the result of the following query?

SQL Code
SELECT JSON_ARRAYAGG(name) FROM employees;
Q19
Single Choice

What will be the output of the following MySQL query?

SQL Code
SELECT JSON_DEPTH('{"name": "John", "address": {"city": "New York", "zip": "10001"}}');
Q20
Single Choice

In MySQL, which of the following operations will raise an error?

SQL Code
INSERT INTO orders (details) VALUES ('{"order_id": 123, "amount": 250}');
Q21
Multiple Choice

Which SQL command defines a column with a JSON data type in PostgreSQL?

SQL Code
CREATE TABLE users (
 user_id SERIAL PRIMARY KEY,
 user_data JSON NOT NULL
);
Q22
Multiple Choice

Which SQL command defines a column with a JSONB data type in PostgreSQL?

SQL Code
CREATE TABLE logs (
 log_id SERIAL PRIMARY KEY,
 log_data JSONB NOT NULL
);
Q23
Multiple Choice

Which SQL command creates a table with a JSON column that has a default value in PostgreSQL?

SQL Code
CREATE TABLE orders (
 order_id SERIAL PRIMARY KEY,
 order_details JSON NOT NULL DEFAULT '{}'
);
Q24
Multiple Choice

Which SQL command creates a table with a JSON column and a constraint that ensures valid JSON data in PostgreSQL?

SQL Code
CREATE TABLE settings (
 setting_id SERIAL PRIMARY KEY,
 config JSON NOT NULL,
 CONSTRAINT valid_json CHECK (jsonb_typeof(config) IS NOT NULL)
);
Q25
Multiple Choice

Which SQL command creates a table with a JSONB column and indexes a specific field within the JSONB data in PostgreSQL?

SQL Code
CREATE TABLE products (
 product_id SERIAL PRIMARY KEY,
 product_info JSONB NOT NULL
);
CREATE INDEX idx_product_info ON products USING gin ((product_info->>'name'));
Q26
Multiple Choice

Which SQL command alters an existing table to add a JSON column in PostgreSQL?

SQL Code
ALTER TABLE users
ADD COLUMN preferences JSON DEFAULT '{}';
Q27
Multiple Choice

Which SQL command creates a table with a JSON column that includes nested JSON data in PostgreSQL?

SQL Code
CREATE TABLE reports (
 report_id SERIAL PRIMARY KEY,
 report_data JSONB NOT NULL
);

INSERT INTO reports (report_data) VALUES ('{"meta": {"author": "John", "created": "2024-01-01"}}');
Q28
Multiple Choice

Which SQL command creates a table with a JSONB column and a partial index in PostgreSQL?

SQL Code
CREATE TABLE sessions (
 session_id SERIAL PRIMARY KEY,
 session_data JSONB NOT NULL
);

CREATE INDEX idx_active_sessions ON sessions USING gin (session_data) WHERE (session_data->>'active') = 'true';
Q29
Multiple Choice

Which SQL command creates a table with a JSONB column and uses a function to extract data from the JSONB column in PostgreSQL?

SQL Code
CREATE TABLE config (
 config_id SERIAL PRIMARY KEY,
 config_data JSONB NOT NULL
);

SELECT config_data->>'setting' AS setting FROM config WHERE config_data->>'setting' = 'enabled';
Q30
Multiple Choice

Which SQL command creates a table with a JSON column and checks for the existence of a key within the JSON data in PostgreSQL?

SQL Code
CREATE TABLE settings (
 setting_id SERIAL PRIMARY KEY,
 setting_data JSONB NOT NULL
);

SELECT * FROM settings WHERE setting_data ? 'theme';