Bird
0
0

Given the table CREATE TABLE orders (id SERIAL, info JSONB); and the insert INSERT INTO orders (info) VALUES ('{"item":"book","qty":3}');, what will the query SELECT info->>'item' FROM orders WHERE id=1; return?

medium📝 query result Q4 of 15
PostgreSQL - JSON and JSONB
Given the table CREATE TABLE orders (id SERIAL, info JSONB); and the insert INSERT INTO orders (info) VALUES ('{"item":"book","qty":3}');, what will the query SELECT info->>'item' FROM orders WHERE id=1; return?
Abook
B3
C{"item":"book","qty":3}
DNULL
Step-by-Step Solution
Solution:
  1. Step 1: Understand JSONB operator ->>

    The operator ->> extracts the JSON value as text for the given key.
  2. Step 2: Apply operator to 'item' key

    Extracting 'item' returns the string "book" stored in JSONB column.
  3. Final Answer:

    book -> Option A
  4. Quick Check:

    JSONB ->> operator extracts text value [OK]
Quick Trick: Use ->> to get JSON value as text [OK]
Common Mistakes:
  • Using -> instead of ->> and expecting text
  • Expecting full JSON object instead of value
  • Confusing key names or values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes