gpt4 book ai didi

postgresql - 为什么没有列的 SELECT 有效

转载 作者:行者123 更新时间:2023-11-29 12:24:23 26 4
gpt4 key购买 nike

我不小心写了一个类似 select from my_table; 的查询,令人惊讶的是它是有效的语句。对我来说更有趣的是,甚至 SELECT; 在 PostgreSQL 中也是一个有效的查询。你可以尝试用这个写很多有趣的查询:

select union all select;
with t as (select) select;
select from (select) a, (select) b;
select where exists (select);
create table a (b int); with t as (select) insert into a (select from t);

这是某种定义 SQL 标准的结果,还是它有一些用例,或者它只是一种有趣的行为,没有人愿意以编程方式限制?

最佳答案

Right from the manual:

The list of output expressions after SELECT can be empty, producing a zero-column result table. This is not valid syntax according to the SQL standard. PostgreSQL allows it to be consistent with allowing zero-column tables. However, an empty list is not allowed when DISTINCT is used.

如果我没记错的话,“零列”表的可能性是表继承的副作用。在 Postgres 邮件列表上对此进行了讨论(但我现在找不到)

关于postgresql - 为什么没有列的 SELECT 有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48713991/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com