I stumbled upon very odd behavior with unnest(), when casting after expanding an array.
There are three basic syntax variants to use unnest():
Casting SRF function (in FROM clause) is not supported - you cannot use any operator there. Only function call is allowed.
a cast is possible only in column list:
postgres=# SELECT * FROM unnest('{2,NULL,1}'::int[])::text;
ERROR: syntax error at or near "::"
LINE 1: SELECT * FROM unnest('{2,NULL,1}'::int[])::text;
^
postgres=# SELECT v::text FROM unnest('{2,NULL,1}'::int[]) g(v);
v
────────
2
[null]
1
(3 rows)
Missing row from NULL is probably bug and should be reported
postgres=# SELECT unnest('{1,NULL,4}'::int[])::text;
unnest
────────
1
[null]
4
(3 rows)
postgres=# SELECT unnest('{1,NULL,4}'::int[])::numeric;
unnest
────────
1
4
(2 rows)
There is not reason, why NULL rows should be dropped, I think