The (2, 3)
has type record, i.e. Postgres doesn't know which (or even how many) columns it contains. You can use the .*
syntax only with known ("registered") types.
You could define your own tuple type and use that instead of a record:
CREATE TYPE tuple AS (a int, b int);
SELECT 1, (CASE WHEN TRUE THEN '(2, 3)'::tuple ELSE '(4, 5)' END).*;
SELECT 1, (CASE WHEN TRUE THEN (2, 3)::tuple ELSE (4, 5)::tuple END).*;
If you absolutely need to have an expression that returns records, you can cast those to tuple
s afterwards only by going through a text
representation:
SELECT 1, ((CASE WHEN TRUE THEN (2, 3) ELSE (4, 5) END)::text::TUPLE).*;
(online demo)