Bird
0
0

Which of the following is the correct syntax to extract a value from a JSON column named data using dbt's SQL with PostgreSQL syntax?

easy📝 Syntax Q12 of 15
dbt - Advanced Patterns
Which of the following is the correct syntax to extract a value from a JSON column named data using dbt's SQL with PostgreSQL syntax?
ASELECT data->name AS name FROM table_name;
BSELECT data->>'name' AS name FROM table_name;
CSELECT data['name'] AS name FROM table_name;
DSELECT data->>name AS name FROM table_name;
Step-by-Step Solution
Solution:
  1. Step 1: Identify PostgreSQL JSON extraction syntax

    PostgreSQL uses ->> to extract JSON text values by key as text.
  2. Step 2: Apply correct syntax to extract 'name'

    The correct syntax is data->>'name' to get the text value of the 'name' key.
  3. Final Answer:

    SELECT data->>'name' AS name FROM table_name; -> Option B
  4. Quick Check:

    PostgreSQL JSON text extraction = data->>'key' [OK]
Quick Trick: Use ->> with quotes for JSON text extraction in PostgreSQL [OK]
Common Mistakes:
MISTAKES
  • Using square brackets instead of ->>
  • Missing quotes around the key name
  • Using -> instead of ->> for text extraction

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes