There is no "STRUCT" in Postgres.
To cast to an array, pass typed element values to an ARRAY constructor (or live with the default element type):
SELECT ARRAY[1,2,3]; --> type int[]
SELECT ARRAY[[1,2,3],[4,5,6]]; --> type int[]
Array types can hold any number of nested dimensions, it's still the same type on the outside to Postgres.
Or cast an array literal to a specific array type:
SELECT '{1,2,3}'::int[]; --> type int[]
SELECT '{{1,2,3},{4,5,6}}'::int[]; --> type int[]
To form an arbitrary "record", i.e. an anonymous ROW type, a.k.a. "composite type", use the ROW constructor:
SELECT ROW('x', 1); --> anonymous row type
(The keyword ROW
is optional in most contexts.)
But named (registered) composite types (ROW types) are more useful in most contexts, as Postgres knows how to properly de-compose it:
SELECT ('x', 1)::my_registered_row_type; --> well-known row type
Every table, view, or materialized view in the same database registers a row type implicitly. Or create a composite type explicitly.
What you show as "RECORD" looks like a JSON value. There are two data types for that in Postgres, json
and jsonb
...
Related: