我需要运行一个选择而不实际连接到任何表.我只需要一个预定义的硬编码值集,我需要循环:
foo
bar
fooBar
Run Code Online (Sandbox Code Playgroud)
我想循环遍历这些价值观.我可以:
select 'foo', 'bar', 'fooBar';
Run Code Online (Sandbox Code Playgroud)
但是这将它作为一行返回:
?column? | ?column? | ?column?
----------+----------+----------
foo | bar | fooBar
(1 row)
Run Code Online (Sandbox Code Playgroud)
我正在使用Postgresql.
Clo*_*eto 83
select a
from (
values ('foo'), ('bar'), ('fooBar')
) s(a);
Run Code Online (Sandbox Code Playgroud)
http://www.postgresql.org/docs/current/static/queries-values.html
Viv*_* S. 16
运用 unnest()
将数组扩展为一组行
select unnest(array['foo', 'bar', 'fooBar']);
Run Code Online (Sandbox Code Playgroud)
小智 11
Postgres SQL:
对于作为单行和多列表示形式的静态数据输出,请使用以下查询:
select a,b,c from (values('foo','bar','fooBar')) s(a,b,c);
Run Code Online (Sandbox Code Playgroud)
此 SQL 查询的结果: