0
0
PostgreSQLquery~5 mins

Creating JSON columns in PostgreSQL - Quick Revision & Summary

Choose your learning style9 modes available
Recall & Review
beginner
What is a JSON column in PostgreSQL?
A JSON column stores JSON (JavaScript Object Notation) data directly in a table, allowing you to save structured data like objects or arrays inside a single column.
Click to reveal answer
beginner
How do you create a JSON column in a PostgreSQL table?
Use the CREATE TABLE statement with a column type json or jsonb. For example: <br>CREATE TABLE example (data jsonb);
Click to reveal answer
intermediate
What is the difference between json and jsonb types in PostgreSQL?
json stores JSON data as text, preserving formatting. jsonb stores JSON in a binary format, which is faster for searching and indexing.
Click to reveal answer
beginner
Can you insert JSON data directly into a JSON column?
Yes, you can insert JSON data as a string. For example: <br>INSERT INTO example (data) VALUES ('{"name": "Alice", "age": 30}');
Click to reveal answer
intermediate
Why use JSON columns instead of multiple regular columns?
JSON columns let you store flexible, nested data without changing the table structure. This is useful when data varies or has many optional fields.
Click to reveal answer
Which PostgreSQL data type is best for storing JSON data with efficient querying?
Ajsonb
Btext
Cvarchar
Djsontext
How do you define a JSON column named 'info' in a new table?
ACREATE TABLE t (info jsonb);
BCREATE TABLE t (info string);
CCREATE TABLE t (info jsontext);
DCREATE TABLE t (info varchar);
Which statement is true about the json type?
AIt automatically indexes JSON keys.
BIt stores JSON in binary format.
CIt cannot store arrays.
DIt stores JSON as plain text preserving formatting.
What is a benefit of using JSON columns in a database?
AFaster than all relational columns for all queries.
BStore flexible, nested data without changing table schema.
CAutomatically encrypts data.
DPrevents any data duplication.
How do you insert JSON data into a JSON column?
AINSERT INTO table (col) VALUES (jsonb_parse);
BINSERT INTO table (col) VALUES (key: value);
CINSERT INTO table (col) VALUES ('{"key": "value"}');
DINSERT INTO table (col) VALUES (json_object);
Explain how to create a JSON column in PostgreSQL and why you might choose jsonb over json.
Think about storage format and query performance differences.
You got /4 concepts.
    Describe a real-life scenario where using a JSON column in a database table is helpful.
    Imagine storing user profiles with optional fields.
    You got /4 concepts.