Q1
True / FalsePostgreSQL allows storing JSON data directly in its tables.
PostgreSQL supports the JSON data type, allowing JSON data to be stored and queried directly in tables
Q2
True / FalseThe JSON data type in PostgreSQL automatically validates JSON syntax on insertion.
When inserting data into a JSON column, PostgreSQL ensures the data is valid JSON format.
Q3
True / FalsePostgreSQL can only store JSON data as text strings.
PostgreSQL has specific JSON and JSONB data types designed to store JSON data efficiently.
Q4
True / FalsePostgreSQL’s JSONB type is more efficient for indexing and querying compared to the JSON type.
JSONB stores JSON data in a binary format, which is more efficient for indexing and querying.
Q5
True / FalseYou can use the ->> operator to extract an element from a JSON array in PostgreSQL.
The ->> operator is used to extract a JSON object field as text, not to extract an element from a JSON array. For JSON arrays, use the -> operator.
Q6
True / FalsePostgreSQL provides functions to transform JSON data into PostgreSQL rows and vice versa.
PostgreSQL offers functions like json_to_record and json_to_recordset to convert JSON data to rows, and row_to_json to transform rows into JSON.
Q7
True / FalseIn PostgreSQL, indexing a JSONB column with a GIN index allows for efficient search of nested keys and values.
GIN indexes are particularly effective for JSONB columns, providing fast access to nested keys and values.
Q8
True / FalsePostgreSQL’s JSONB type preserves the original formatting and ordering of JSON data.
JSONB does not preserve the original formatting or ordering of JSON data; it stores data in a binary format optimized for search.
Q9
True / FalseYou can use the jsonb_set function in PostgreSQL to update a value in a JSONB column.
The jsonb_set function allows you to update a value within a JSONB column without replacing the entire JSON document.
Q10
True / FalsePostgreSQL's JSONB type is always preferred over JSON for all types of operations because it is universally more efficient.
While JSONB is generally more efficient for indexing and querying, JSON might be preferred in scenarios where maintaining the original text formatting and ordering of JSON data is critical, or for certain operations where the overhead of converting to binary is not justified.
Q27
Multiple ChoiceWhich 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"}}');
This command creates a 'reports' table with a JSONB column 'report_data' and inserts nested JSON data into this column, demonstrating how JSON data can be structured.