Bird
0
0

You try to create a table with a JSON column using:

medium📝 Debug Q14 of 15
PostgreSQL - JSON and JSONB
You try to create a table with a JSON column using:
CREATE TABLE users (id INT, profile JSONB DEFAULT {});
But get a syntax error. What is the problem?
AMissing quotes around the default JSON value
BJSONB columns cannot have default values
CEmpty braces {} are not valid default for JSONB
DINT type cannot be used with JSONB columns
Step-by-Step Solution
Solution:
  1. Step 1: Check default value syntax for JSONB

    Default JSON values must be valid JSON strings, so '{}' must be in single quotes.
  2. Step 2: Identify the error cause

    Using {} without quotes causes syntax error. Correct is DEFAULT '{}'.
  3. Final Answer:

    Missing quotes around the default JSON value -> Option A
  4. Quick Check:

    Default JSON must be quoted [OK]
Quick Trick: Always quote JSON default values as strings [OK]
Common Mistakes:
  • Using unquoted braces {} as default
  • Assuming JSONB cannot have defaults
  • Confusing data types in table definition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes