Bird
0
0

What is the output of this query?

medium📝 query result Q13 of 15
PostgreSQL - Set Operations and Advanced Queries
What is the output of this query?
SELECT * FROM (VALUES (1, 'Red'), (2, 'Blue')) AS colors(id, name);
AOne row with array [(1, 'Red'), (2, 'Blue')]
BSyntax error due to missing table
CEmpty result set
DTwo rows with columns id and name: (1, 'Red') and (2, 'Blue')
Step-by-Step Solution
Solution:
  1. Step 1: Understand VALUES with alias

    The VALUES clause creates two rows. The alias 'colors' names the columns as id and name.
  2. Step 2: Result of SELECT * from VALUES

    The query returns two rows: first row (1, 'Red'), second row (2, 'Blue'), with columns id and name.
  3. Final Answer:

    Two rows with columns id and name: (1, 'Red') and (2, 'Blue') -> Option D
  4. Quick Check:

    VALUES + alias = rows with named columns [OK]
Quick Trick: VALUES with alias returns rows with named columns [OK]
Common Mistakes:
  • Expecting a syntax error without a real table
  • Thinking VALUES returns arrays
  • Assuming empty results without data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes