在 Postgres 中,ANY
和 SOME
在谓词表达式的右侧使用时是同义词。例如,它们是相同的:
column = ANY (SELECT ...)
column = SOME (SELECT ...)
此处记录:
http://www.postgresql.org/docs/9.1/static/functions-subquery.html#FUNCTIONS-SUBQUERY-ANY-SOME
我观察到ANY
和 SOME
至少受以下 SQL DBMS 支持:
- DB2
- Derby
- H2
- HSQLDB
- Ingres
- MySQL
- Oracle
- Postgres
- SQL Server
- Sybase ASE
- Sybase SQL Anywhere
我可以安全地假设所有这些方言(以及其他方言)将 ANY
和 SOME
视为同义词,或者在任何/某些 DBMS 中这两个关键字之间是否存在细微差别?
我在 SQL92 定义中发现了这一点:
<quantifier> ::= <all> | <some>
<all> ::= ALL
<some> ::= SOME | ANY
这并没有说明 ANY
和 SOME
的语义。稍后在文档中,仅引用了
,而不是这两个关键字。我怀疑 NULL
处理可能存在细微差别,例如,至少在某些 DBMS 中。欢迎任何/一些指向明确声明是否可以假设的指针。
In Postgres, ANY
and SOME
are synonyms when used on the right hand side of a predicate expression. For example, these are the same:
column = ANY (SELECT ...)
column = SOME (SELECT ...)
This is documented here:
http://www.postgresql.org/docs/9.1/static/functions-subquery.html#FUNCTIONS-SUBQUERY-ANY-SOME
I have observed ANY
and SOME
to be supported by at least these SQL DBMSs:
- DB2
- Derby
- H2
- HSQLDB
- Ingres
- MySQL
- Oracle
- Postgres
- SQL Server
- Sybase ASE
- Sybase SQL Anywhere
Can I safely assume that all of those dialects (and others, too) treat ANY
and SOME
as synonyms or is there a subtle difference between the two keywords in any/some DBMS?
I have found this in the SQL92 definition:
<quantifier> ::= <all> | <some>
<all> ::= ALL
<some> ::= SOME | ANY
This doesn't say anything about the semantics of ANY
and SOME
. Later on in the document, only <some>
is referenced, not the two keywords. I'm suspecting that there might be a subtle difference in NULL
handling, for instance, at least in some DBMSs. Any/some pointer to a clear statement whether this can be assumed or not is welcome.
发布评论
评论(1)
在您引用的内容之后几行,SQL92 标准还指定了
的语义,即:这些规则适用于
标记,独立关于它是 SOME 还是 ANY 的替代品,所以是的,根据标准它们是同义词Few lines after what you're quoting, the SQL92 standard also specifies the semantics for
<some>
, namely:These rules apply for the
<some>
token, independent on whether it is the SOME or ANY alternative, so yes, they are synonyms according to the standard