本文介绍了为什么没有列的SELECT有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不小心写了一个查询,例如my_table中的 select; ,令人惊讶的是它是有效的语句。对我来说更有趣的是,即使 SELECT; 在PostgreSQL中也是有效的查询。您可以尝试使用以下代码编写很多有趣的查询:

I accidently wrote a query like select from my_table; and surprisingly it is valid statement. Even more interesting to me is that even SELECT; is a valid query in PostgreSQL. You can try to write a lot funny queries with this:

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标准的结果,还是有一定的用例?

Is this a consequence of some definition SQL standard, or there is some use case for it, or it is just funny behavior that no one cared to programatically restrict?

推荐答案

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

The possibility of "zero-column" tables is a side effect of the table inheritance if I'm not mistaken. There were discussions over this on the Postgres mailing lists (but I can't find them right now)

这篇关于为什么没有列的SELECT有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 01:15