I'm attempting to write a SELECT query which returns a RECORD of ROWS.
I've solved half of the problem, as in I can get a RECORD to return a single ROW. But what about returning a set of ROWS?
Take the following query for example:
SELECT * FROM
RECORD(
(
ROW(1::integer, 'Florida'::character varying)
)
) AS tbl (id integer, state character varying)
I get what I anticipate:
+==============+
| id | state |
+====+=========+
| 1 | Florida |
+----+---------+
However, when I attempt to add one additional ROW to the RECORD, this is where I encounter problems:
SELECT * FROM
RECORD(
(
ROW(1::integer, 'Florida'::character varying),
ROW(2::integer, 'Georgia'::character varying)
)
) AS tbl (id integer, state character varying)
I would anticipate a result similar to:
+==============+
| id | state |
+====+=========+
| 1 | Florida |
+----+---------+
| 2 | Georgia |
+----+---------+
However, I receive the following PostgreSQL errors instead:
********** Error **********
ERROR: function return row and query-specified return row do not match
SQL state: 42804
Detail: Returned type record at ordinal position 1, but query expects integer.
What is it I'm missing here? Something trivial, or am I approaching this all wrong? Any pointers or suggestions is greatly appreciated, and thank you!
On a related note: I understand that if this was to take place in a stored procedure I could return a SETOF, however for this use case I'm interested in returning a RECORD of ROWS directly through a query without the use of a stored procedure.