0
0
PostgreSQLquery~5 mins

Inserting JSON data in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the correct SQL command to insert JSON data into a PostgreSQL table?
Use the INSERT INTO statement with a column of type json or jsonb. The JSON data should be provided as a string literal enclosed in single quotes.
Click to reveal answer
beginner
What data types in PostgreSQL are used to store JSON data?
PostgreSQL provides two data types for JSON: json which stores JSON as text, and jsonb which stores JSON in a binary format for faster processing.
Click to reveal answer
beginner
How do you insert a JSON object into a table column of type jsonb?
You insert JSON data as a string literal. For example: <br>INSERT INTO table_name (json_column) VALUES ('{"key": "value"}');
Click to reveal answer
beginner
Can you insert JSON arrays into PostgreSQL JSON columns?
Yes, you can insert JSON arrays as string literals just like JSON objects. For example: <br>INSERT INTO table_name (json_column) VALUES ('[1, 2, 3]');
Click to reveal answer
beginner
What happens if you try to insert invalid JSON into a JSON or JSONB column?
PostgreSQL will return an error because the data must be valid JSON format to be stored in json or jsonb columns.
Click to reveal answer
Which PostgreSQL data type is optimized for faster JSON processing?
Ajsonb
Bjson
Ctext
Dvarchar
How should JSON data be formatted when inserting into a PostgreSQL JSON column?
AAs a number
BAs a string literal enclosed in single quotes
CAs a plain JSON object without quotes
DAs a SQL function
What will happen if you insert invalid JSON text into a JSON column?
APostgreSQL will convert it automatically
BPostgreSQL will accept it as text
CPostgreSQL will throw an error
DPostgreSQL will ignore the invalid parts
Which SQL command is used to add JSON data to a table?
AINSERT INTO
BSELECT
CUPDATE
DDELETE
Can you insert a JSON array into a PostgreSQL JSON column?
AOnly with special functions
BNo, only JSON objects are allowed
COnly if converted to text first
DYes, as a string literal
Explain how to insert JSON data into a PostgreSQL table column.
Think about the SQL command and how JSON is represented as text.
You got /4 concepts.
    What are the differences between json and jsonb data types in PostgreSQL?
    Consider storage format and performance.
    You got /4 concepts.