在所有 SQL 方言中,SQL ANY 和 SOME 关键字是同义词吗? [英] Are SQL ANY and SOME keywords synonyms in all SQL dialects?
问题描述
在 Postgres 中,ANY
和 SOME
在谓词表达式的右侧使用时是同义词.例如,这些是相同的:
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 ...)
这在此处记录:
http://www.postgresql.org/docs/9.1/static/functions-subquery.html#FUNCTIONS-SUBQUERY-ANY-SOME
我观察到至少这些 SQL DBMS 支持 ANY
和 SOME
:
I have observed ANY
and SOME
to be supported by at least these SQL DBMSs:
- DB2
- 德比
- H2
- HSQLDB
- 入口
- MySQL
- 甲骨文
- Postgres
- SQL 服务器
- Sybase ASE
- Sybase SQL Anywhere
我可以安全地假设所有这些方言(以及其他方言)都将 ANY
和 SOME
视为同义词,或者在任何方言中这两个关键字之间是否存在细微差别?/一些数据库管理系统?
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?
我在 SQL92 定义中找到了这个:
I have found this in the SQL92 definition:
<quantifier> ::= <all> | <some>
<all> ::= ALL
<some> ::= SOME | ANY
这并没有说明 ANY
和 SOME
的语义.稍后在文档中,仅引用了 <some>
,而不是这两个关键字.我怀疑 NULL
处理可能存在细微差别,例如,至少在某些 DBMS 中.欢迎任何/一些指向明确声明是否可以假设的指针.
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.
推荐答案
在你引用的几行之后,SQL92 标准还指定了 <some>
的语义,即:p>
Few lines after what you're quoting, the SQL92 standard also specifies the semantics for <some>
, namely:
c) If the implied <comparison predicate> is true for at least
one row RT in T, then "R <comp op> <some> T" is true.
d) If T is empty or if the implied <comparison predicate> is
false for every row RT in T, then "R <comp op> <some> T" is
false.
e) If "R <comp op> <quantifier> T" is neither true nor false,
then it is unknown.
这些规则适用于 <some>
标记,与它是 SOME 还是 ANY 替代无关,所以是的,根据标准,它们是同义词
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
这篇关于在所有 SQL 方言中,SQL ANY 和 SOME 关键字是同义词吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!