How to create an empty anonymous table in Postgres?
In Postgres if I want to create an anonymous table I can use VALUES, for
example:
select * from (values (1, 'Hello world'), (100, 'Another row')) as foo
(mycol1, mycol2);
But how can I create an anonymous table with no rows? (This is for a code
generator, so the question isn't quite as odd as it sounds!). The
following does not work
select * from (values ) as foo (mycol1, mycol2);
because I get
ERROR: syntax error at or near ")"
LINE 1: select * from (values ) as foo (mycol1, mycol2);
^
I know a work around
select * from (values (NULL, NULL)) as foo (mycol1, mycol2) where mycol1
is not NULL;
but is there a better or "more official" way?
(I would also be interested to know if it is possible to create a table
with no columns!)
No comments:
Post a Comment