Subqueries & Set Operations — Series 3

Preview — 3 of 10 questions

What does WHERE price > SOME (SELECT price FROM competitor_prices) mean, compared to using ANY instead of SOME?

ASOME and ANY are exact synonyms in PostgreSQL — the query is true if price exceeds at least one competitor price
BSOME requires the row to exceed every competitor price, unlike ANY
CSOME is not valid PostgreSQL syntax; only ANY exists
DSOME only works with IN, never with a comparison operator like >

What is the relationship between WHERE status IN ('active', 'pending') and WHERE status = ANY(ARRAY['active', 'pending'])?

AThey're unrelated — IN is a completely separate mechanism from ANY
BIN (...) with a literal list is defined equivalently to = ANY(ARRAY[...]) — PostgreSQL treats the static IN list as shorthand for comparing equality against any element of that set, the same underlying semantics used when ANY wraps a subquery
C= ANY(...) is strictly faster because it avoids parsing a list
DIN only works with subqueries; ANY only works with array literals

Given GROUP BY CUBE (region, product) versus GROUP BY ROLLUP (region, product), what's the difference in which subtotal rows each produces?

AThey're identical; CUBE is just a legacy alias for ROLLUP
BROLLUP produces subtotals for every possible combination of the two columns, including one with neither; CUBE only produces the hierarchical subtotals (both, region-only, grand total)
CROLLUP (region, product) produces a hierarchical set of subtotals — (region, product), (region), and () (grand total) — respecting column order; CUBE (region, product) produces subtotals for every combination — (region, product), (region), (product), and () — including the (product)-only breakdown that ROLLUP skips
DCUBE can only be used with numeric columns, never text columns like region

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.