Select hardcoded values without table
I need to run a select without actually connecting to any table. I just have a predefined hardcoded set of values I need to loop over:
foo
bar
fooBar
And I want to loop through those values. I can do:
select 'foo', 'bar', 'fooBar';
But this returns it as one row:
?column? | ?column? | ?column?
----------+----------+----------
foo | bar | fooBar
(1 row)
I am using Postgresql.
select a
from (
values ('foo'), ('bar'), ('fooBar')
) s(a);
http://www.postgresql.org/docs/current/static/queries-values.html
Using unnest()
expand an array to a set of rows
select unnest(array['foo', 'bar', 'fooBar']);
demo
Postgres SQL:
For static data output as single row and multiple columns representation use following query:
select a,b,c from (values('foo','bar','fooBar')) s(a,b,c);
result of this SQL query: