Bird
0
0

Given the composite type and table:

medium📝 query result Q4 of 15
PostgreSQL - Advanced Features
Given the composite type and table:
CREATE TYPE address AS (city text, zip integer);
CREATE TABLE users (id serial PRIMARY KEY, name text, addr address);

What will be the output of this query?
SELECT (addr).city FROM users WHERE id = 1;
AReturns the city value from the addr composite field for user with id 1
BReturns the entire addr composite value as text
CReturns an error because composite fields cannot be accessed this way
DReturns NULL always
Step-by-Step Solution
Solution:
  1. Step 1: Understand composite field access

    Using (addr).city extracts the city field from the composite type addr.
  2. Step 2: Analyze query behavior

    The query returns the city value for the user with id 1.
  3. Final Answer:

    Returns the city value from the addr composite field for user with id 1 -> Option A
  4. Quick Check:

    Composite field access = (composite).field [OK]
Quick Trick: Use (composite_column).field to get specific field value [OK]
Common Mistakes:
  • Trying to access composite fields without parentheses
  • Expecting entire composite as text automatically
  • Assuming syntax causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes