Bird
0
0

Which of the following is the correct syntax to insert JSON data into a table named users with a jsonb column info?

easy📝 Syntax Q12 of 15
PostgreSQL - JSON and JSONB
Which of the following is the correct syntax to insert JSON data into a table named users with a jsonb column info?
AINSERT INTO users (info) VALUES (jsonb '{"city": "NY", "zip": 10001}');
BINSERT INTO users (info) VALUES ('{city: "NY", zip: 10001}');
CINSERT INTO users (info) VALUES ("{'city': 'NY', 'zip': 10001}");
DINSERT INTO users (info) VALUES (jsonb '{city: NY, zip: 10001}');
Step-by-Step Solution
Solution:
  1. Step 1: Use jsonb type cast for jsonb columns

    When inserting into a jsonb column, you can cast the string to jsonb using jsonb '...' .
  2. Step 2: Use valid JSON string with double quotes inside single quotes

    The JSON must be valid with double quotes around keys and string values.
  3. Final Answer:

    INSERT INTO users (info) VALUES (jsonb '{"city": "NY", "zip": 10001}'); -> Option A
  4. Quick Check:

    jsonb cast with valid JSON string = C [OK]
Quick Trick: Cast JSON string to jsonb with jsonb '...' for jsonb columns [OK]
Common Mistakes:
  • Using double quotes for the whole JSON string
  • Not casting to jsonb when required
  • Using invalid JSON format without quotes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes