Bird
0
0

What is the correct way to insert JSON data into a PostgreSQL table with a json column named data?

easy📝 Conceptual Q11 of 15
PostgreSQL - JSON and JSONB
What is the correct way to insert JSON data into a PostgreSQL table with a json column named data?
AINSERT INTO table_name (data) VALUES (JSON('name: John, age: 30'));
BINSERT INTO table_name (data) VALUES ({name: 'John', age: 30});
CINSERT INTO table_name (data) VALUES ("{'name': 'John', 'age': 30}");
DINSERT INTO table_name (data) VALUES ('{"name": "John", "age": 30}');
Step-by-Step Solution
Solution:
  1. Step 1: Use single quotes for JSON string in SQL

    In PostgreSQL, JSON data must be enclosed in single quotes as a string literal.
  2. Step 2: Use valid JSON format inside the string

    The JSON must have double quotes around keys and string values, like {"name": "John", "age": 30}.
  3. Final Answer:

    INSERT INTO table_name (data) VALUES ('{"name": "John", "age": 30}'); -> Option D
  4. Quick Check:

    JSON string with single quotes and double quotes inside = D [OK]
Quick Trick: Always use single quotes around JSON string in SQL [OK]
Common Mistakes:
  • Using double quotes for the whole JSON string
  • Using unquoted keys or single quotes inside JSON
  • Trying to insert JSON without quotes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes