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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 00:08:17  来源:igfitidea点击:

Select hardcoded values without table

postgresql

提问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 Vivek S.

Using unnest()

使用 unnest()

expand an array to a set of rows

将数组扩展为一组行

select unnest(array['foo', 'bar', 'fooBar']);

demo

演示