Ambiguous usage of 'any' in explanation
The following documentation comment has been logged on the website:
Page: https://www.postgresql.org/docs/10/static/functions-subquery.html
Description:
Hi.
The [DOC](https://www.postgresql.org/docs/10/static/functions-subquery.html)
says:
The result is NULL if the comparison does not return false for any
subquery row
does *any* mean here: some or all?
For example in
[MySQL](https://dev.mysql.com/doc/refman/8.0/en/any-in-some-subqueries.html)
I have found this explanation:
Use of the word SOME is rare, but this example shows why it might be
useful. To most people, the English phrase “a is not equal to any b” means
“there is no b which is equal to a,” but that is not what is meant by the
SQL syntax. The syntax means “there is some b to which a is not equal.”
Using <> SOME instead helps ensure that everyone understands the true
meaning of the query.
On Sat, Sep 15, 2018 at 11:53:47AM +0000, PG Doc comments form wrote:
The following documentation comment has been logged on the website:
Page: https://www.postgresql.org/docs/10/static/functions-subquery.html
Description:Hi.
The [DOC](https://www.postgresql.org/docs/10/static/functions-subquery.html)
says:The result is NULL if the comparison does not return false for any
subquery rowdoes *any* mean here: some or all?
For example in
[MySQL](https://dev.mysql.com/doc/refman/8.0/en/any-in-some-subqueries.html)
I have found this explanation:Use of the word SOME is rare, but this example shows why it might be
useful. To most people, the English phrase “a is not equal to any b” means
“there is no b which is equal to a,” but that is not what is meant by the
SQL syntax. The syntax means “there is some b to which a is not equal.”
Using <> SOME instead helps ensure that everyone understands the true
meaning of the query.
I am kind of confused by this report. You mention SOME in the text
above, which is a synonym for ANY, but the text you quote:
The result is NULL if the comparison does not return false for any
subquery row
is from ALL:
The result of <token>ALL</token> is <quote>true</quote> if
the comparison returns true for all subquery rows (including
the case where the subquery returns no rows). The result is
<quote>false</quote> if the comparison returns false for any
subquery row. The result is NULL if the comparison does not
return false for any subquery row, and it returns NULL for at
least one row.
I see the last line is just trying to negate the line above it, but the
mix of "not" and "any" is confusing. I can reword this last line to be:
The result is NULL if no comparison with a subquery row returns
false, and it returns NULL for at least one row.
I can make similar adjustments in other places, and have attached a doc
patch. Does that help?
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ As you are, so once was I. As I am, so you will be. +
+ Ancient Roman grave inscription +
Attachments:
any.difftext/x-diff; charset=us-asciiDownload+4-4
On Thursday, October 11, 2018, Bruce Momjian <bruce@momjian.us> wrote:
The result is NULL if no comparison with a subquery row returns
false, and it returns NULL for at least one row.I can make similar adjustments in other places, and have attached a doc
patch. Does that help?
+1
David J.
<div xmlns="http://www.w3.org/1999/xhtml">either it is hard to understand.</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">I will rephrase one part to show how it is easy to understand from my side:</div><div xmlns="http://www.w3.org/1999/xhtml">&gt;ALL</div><div xmlns="http://www.w3.org/1999/xhtml">&gt; The result is <span>“<span>false</span>”</span> if any false result is found.</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">The result of ALL is "false" even if *at least one* row yield false</div><div xmlns="http://www.w3.org/1999/xhtml">(we can use 'some' word here, but it is not such clear as *at least one*)</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">This sentence is easyly can be compared to:</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">&gt;The result of <code>ALL</code> is <span>“<span>true</span>”</span> if all rows yield true</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">We can notice difference with first statement so can understand when result is different:</div><div xmlns="http://www.w3.org/1999/xhtml">(I got next picture in my mind in this case:)</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml"> all true -> true</div><div xmlns="http://www.w3.org/1999/xhtml"> at least one false -> false</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">Thus if other parts of DOC would be constructed in same manner, it would be cool</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">PS. When DOC not just document behavior but also allow eaisly detect difference when/why behavior of a command is changed.</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">Thank you.</div><div><br /></div><div><br /></div><div>12.10.2018, 00:20, "David G. Johnston" <david.g.johnston@gmail.com>:</div><blockquote type="cite">On Thursday, October 11, 2018, Bruce Momjian <<a href="mailto:bruce@momjian.us">bruce@momjian.us</a>> wrote:<blockquote style="margin:0 0 0 0.8ex;border-left:1px #ccc solid;padding-left:1ex;">
The result is NULL if no comparison with a subquery row returns<br />
false, and it returns NULL for at least one row.<br />
<br />
I can make similar adjustments in other places, and have attached a doc<br />
patch. Does that help?<br />
</blockquote><div><br /></div><div>+1</div><div><br /></div><div>David J. </div>
</blockquote>
<div xmlns="http://www.w3.org/1999/xhtml">- The result is NULL if the comparison does not return true for any row,<br />+ The result is NULL if no comparison with a subquery row returns true,<br /> and it returns NULL for at least one row.</div><div xmlns="http://www.w3.org/1999/xhtml">-The result of <code>ANY</code> is <span>“<span>true</span>”</span> if the comparison returns true for any subquery row. The result is <span>“<span>false</span>”</span> if the comparison returns false for every subquery row (including the case where the subquery returns no rows). The result is NULL if the comparison does not return true for any row, and it returns NULL for at least one row.</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">Similary to:</div><div xmlns="http://www.w3.org/1999/xhtml">&gt;The result of ALL is "false" even if *at least one* row yield false</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">+The result of ANY is "true" if at least one row yields true.</div><div xmlns="http://www.w3.org/1999/xhtml">The result of ANY is "false" if all rows yield false</div><div xmlns="http://www.w3.org/1999/xhtml">The result of ANY is NULL if no one row yelds true and at least one row yields NULL</div><div xmlns="http://www.w3.org/1999/xhtml">When subquery return no rows the result of ANY is "false"</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">sentences are short, easy to spot when and how result is changed</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">12.10.2018, 00:20, "David G. Johnston" <david.g.johnston@gmail.com>:</div><blockquote xmlns="http://www.w3.org/1999/xhtml" type="cite">On Thursday, October 11, 2018, Bruce Momjian <<a href="mailto:bruce@momjian.us">bruce@momjian.us</a>> wrote:<blockquote style="margin:0 0 0 0.8ex;border-left:1px #ccc solid;padding-left:1ex;"> The result is NULL if no comparison with a subquery row returns<br /> false, and it returns NULL for at least one row.<br /><br />I can make similar adjustments in other places, and have attached a doc<br />patch. Does that help?</blockquote><div> </div><div>+1</div><div> </div><div>David J. </div></blockquote>
On Fri, Oct 12, 2018 at 01:42:03PM +0300, KES wrote:
- The result is NULL if the comparison does not return true for any row, + The result is NULL if no comparison with a subquery row returns true, and it returns NULL for at least one row. -The result of ANY is “true” if the comparison returns true for any subquery row. The result is “false” if the comparison returns false for every subquery row (including the case where the subquery returns no rows). The result is NULL if the comparison does not return true for any row, and it returns NULL for at least one row. Similary to:The result of ALL is "false" even if *at least one* row yield false
+The result of ANY is "true" if at least one row yields true.
The result of ANY is "false" if all rows yield false
The result of ANY is NULL if no one row yelds true and at least one row yields
NULL
When subquery return no rows the result of ANY is "false"
sentences are short, easy to spot when and how result is changed
Sorry, but I don't like this wording. The problem is that the
comparison has two row sets --- the left-hand side, and the right-hand
side. Each row on the left-hand side is compared with the row set on
the right. I also don't like people thinking about the result of ANY
since it is really <comparison> ANY that is being used.
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ As you are, so once was I. As I am, so you will be. +
+ Ancient Roman grave inscription +
On Fri, Oct 12, 2018 at 8:04 AM Bruce Momjian <bruce@momjian.us> wrote:
Sorry, but I don't like this wording. The problem is that the
comparison has two row sets --- the left-hand side, and the right-hand
side.
Huh...the left hand side must be a non-set scalar or row constructor.
Each row on the left-hand side is compared with the row set on
the right. I also don't like people thinking about the result of ANY
since it is really <comparison> ANY that is being used.
Then there is some more rewording to be done since: "The result of ANY is
“true” if any true result is obtained." (v10; 9.22.4)
Maybe:
The result of ANY is “true” if the comparison returns true for any subquery
row; otherwise the result is “false” (or NULL if any of the comparisons
result in unknown)
David J.
On Fri, Oct 12, 2018 at 02:37:33PM -0700, David G. Johnston wrote:
On Fri, Oct 12, 2018 at 8:04 AM Bruce Momjian <bruce@momjian.us> wrote:
Sorry, but I don't like this wording. The problem is that the
comparison has two row sets --- the left-hand side, and the right-hand
side.Huh...the left hand side must be a non-set scalar or row constructor.
I meant that each row feeds a value to the left-hand side to be
evaluated.
Each row on the left-hand side is compared with the row set on
the right. I also don't like people thinking about the result of ANY
since it is really <comparison> ANY that is being used.Then there is some more rewording to be done since: "The result of ANY is
“true” if any true result is obtained." (v10; 9.22.4)Maybe:
The result of ANY is “true” if the comparison returns true for any subquery
row; otherwise the result is “false” (or NULL if any of the comparisons result
in unknown)
Sure.
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ As you are, so once was I. As I am, so you will be. +
+ Ancient Roman grave inscription +
<div xmlns="http://www.w3.org/1999/xhtml"><font face="arial, helvetica, sans-serif">>or NULL if any of the comparisons result in unknown</font></div><div xmlns="http://www.w3.org/1999/xhtml">result in unknown??</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div><br /></div><div><br /></div><div>13.10.2018, 00:37, "David G. Johnston" <david.g.johnston@gmail.com>:</div><blockquote type="cite"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div style="font-family:arial,helvetica,sans-serif;"><span style="font-family:Arial,Helvetica,sans-serif;">On Fri, Oct 12, 2018 at 8:04 AM Bruce Momjian <<a href="mailto:bruce@momjian.us">bruce@momjian.us</a>> wrote:</span><br /></div><div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;">Sorry, but I don't like this wording. The problem is that the<br />
comparison has two row sets --- the left-hand side, and the right-hand<br />
side.</blockquote><div><br /></div><div style="font-family:arial,helvetica,sans-serif;">Huh...the left hand side must be a non-set scalar or row constructor.</div><div><br /></div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;"> Each row on the left-hand side is compared with the row set on<br />
the right. I also don't like people thinking about the result of ANY<br />
since it is really <comparison> ANY that is being used.<br /></blockquote><div><br /></div><div style="font-family:arial,helvetica,sans-serif;">Then there is some more rewording to be done since: "The result of ANY is “true” if any true result is obtained." (v10; 9.22.4)</div><div style="font-family:arial,helvetica,sans-serif;"><br /></div><div style="font-family:arial,helvetica,sans-serif;">Maybe:</div><div style="font-family:arial,helvetica,sans-serif;"><br /></div><div><font face="arial, helvetica, sans-serif">The result of ANY is “true” if the comparison returns true for any subquery row; otherwise the result is “false” (or NULL if any of the comparisons result in unknown)</font><br /></div><div><font face="arial, helvetica, sans-serif"><br /></font></div><div><font face="arial, helvetica, sans-serif">David J.</font></div><div><font face="arial, helvetica, sans-serif"><br /></font></div></div></div></div></div>
</blockquote>
On Sat, Oct 13, 2018 at 12:25:38PM +0300, KES wrote:
or NULL if any of the comparisons result in unknown
result in unknown??
Well, SQL has a three-valued logic, and UNKOWN values are treated like
NULL. For me they have always been the same, and I would like to avoid
"unknown" in this context, if possible.
---------------------------------------------------------------------------
13.10.2018, 00:37, "David G. Johnston" <david.g.johnston@gmail.com>:
On Fri, Oct 12, 2018 at 8:04 AM Bruce Momjian <bruce@momjian.us> wrote:
Sorry, but I don't like this wording. The problem is that the
comparison has two row sets --- the left-hand side, and the right-hand
side.Huh...the left hand side must be a non-set scalar or row constructor.
Each row on the left-hand side is compared with the row set on
the right. I also don't like people thinking about the result of ANY
since it is really <comparison> ANY that is being used.Then there is some more rewording to be done since: "The result of ANY is
“true” if any true result is obtained." (v10; 9.22.4)Maybe:
The result of ANY is “true” if the comparison returns true for any subquery
row; otherwise the result is “false” (or NULL if any of the comparisons
result in unknown)David J.
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ As you are, so once was I. As I am, so you will be. +
+ Ancient Roman grave inscription +
On Saturday, October 13, 2018, Bruce Momjian <bruce@momjian.us> wrote:
On Sat, Oct 13, 2018 at 12:25:38PM +0300, KES wrote:
or NULL if any of the comparisons result in unknown
result in unknown??
Well, SQL has a three-valued logic, and UNKOWN values are treated like
NULL. For me they have always been the same, and I would like to avoid
"unknown" in this context, if possible.
I was just trying to avoid using the word null twice in the same sentence
but it’s not a strong aversion.
David J.
On Sun, Oct 14, 2018 at 11:00:18PM -0700, David G. Johnston wrote:
On Saturday, October 13, 2018, Bruce Momjian <bruce@momjian.us> wrote:
On Sat, Oct 13, 2018 at 12:25:38PM +0300, KES wrote:
or NULL if any of the comparisons result in unknown
result in unknown??
Well, SQL has a three-valued logic, and UNKOWN values are treated like
NULL. For me they have always been the same, and I would like to avoid
"unknown" in this context, if possible.I was just trying to avoid using the word null twice in the same sentence but
it’s not a strong aversion.
I am thinking of applying my earlier patch and calling it done.
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ As you are, so once was I. As I am, so you will be. +
+ Ancient Roman grave inscription +
On Mon, Oct 15, 2018 at 12:32:20PM -0400, Bruce Momjian wrote:
On Sun, Oct 14, 2018 at 11:00:18PM -0700, David G. Johnston wrote:
On Saturday, October 13, 2018, Bruce Momjian <bruce@momjian.us> wrote:
On Sat, Oct 13, 2018 at 12:25:38PM +0300, KES wrote:
or NULL if any of the comparisons result in unknown
result in unknown??
Well, SQL has a three-valued logic, and UNKOWN values are treated like
NULL. For me they have always been the same, and I would like to avoid
"unknown" in this context, if possible.I was just trying to avoid using the word null twice in the same sentence but
it’s not a strong aversion.I am thinking of applying my earlier patch and calling it done.
Applied and backpatched to 9.3.
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ As you are, so once was I. As I am, so you will be. +
+ Ancient Roman grave inscription +