问题
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:
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.
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
来源:https://stackoverflow.com/questions/8771596/are-sql-any-and-some-keywords-synonyms-in-all-sql-dialects