postgresql 选择没有表格的硬编码值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15948614/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Select hardcoded values without table
提问by Richard Knop
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.
我正在使用 Postgresql。
回答by Clodoaldo Neto
select a
from (
values ('foo'), ('bar'), ('fooBar')
) s(a);
http://www.postgresql.org/docs/current/static/queries-values.html
http://www.postgresql.org/docs/current/static/queries-values.html