Unknown returned type in PostgreSQL query
It is ugly, but you can try:
SELECT a, b::text
FROM unnest(ARRAY[(1,'hello'), (3,'world')])
AS t(a integer, b unknown);
This way the type defined in AS
matches the output of unnest()
, which you can cast to your needs in the SELECT
list.
You can try this in a small SQLFiddle.
You can do this without generating a warning by creating a type and casting the records to it:
create type t as (a integer, b varchar(255));
select * from unnest(array[(1,'hello'), (3,'world')]::t[]);
┌───┬───────┐
│ a │ b │
├───┼───────┤
│ 1 │ hello │
│ 3 │ world │
└───┴───────┘
tested on 9.4 and 9.3 (db<>fiddle here)