Bird
0
0

Given the composite type and table:

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

What will the query return?
SELECT (home).city FROM users WHERE id = 1;
AAn error because you cannot access composite fields like this
BThe zip code of the home address for user with id 1
CThe entire home composite value as text
DThe city name stored in the home column for user with id 1
Step-by-Step Solution
Solution:
  1. Step 1: Understand composite field access syntax

    Using (home).city extracts the city field from the composite column home.
  2. Step 2: Analyze the query result

    The query selects city from home for user with id 1, so it returns that city name.
  3. Final Answer:

    The city name stored in the home column for user with id 1 -> Option D
  4. Quick Check:

    (column).field extracts field from composite [OK]
Quick Trick: Use (column).field to get composite field value [OK]
Common Mistakes:
  • Trying to access composite fields without parentheses
  • Expecting entire composite instead of single field
  • Confusing city with zip field

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes