pg.ddx.io pgsql-docs@postgresql.org mailing list archive
help / color / mirror / Atom feedRe: Subscript expressions do not have to evaluate to integers
5+ messages / 3 participants
[nested] [flat]
* Re: Subscript expressions do not have to evaluate to integers
@ 2020-08-22 00:33 Bruce Momjian <bruce@momjian.us>
2020-08-22 01:22 ` Re: Subscript expressions do not have to evaluate to integers Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 5+ messages in thread
From: Bruce Momjian @ 2020-08-22 00:33 UTC (permalink / raw)
To: sean@materialize.io; pgsql-docs@lists.postgresql.org
On Wed, Jul 22, 2020 at 02:59:18AM +0000, PG Doc comments form wrote:
> The following documentation comment has been logged on the website:
>
> Page: https://www.postgresql.org/docs/12/sql-expressions.html
> Description:
>
> Section 4.2.3. Subscripts of the documentation states:
>
> > Each subscript is itself an expression, which must yield an integer
> value.
>
> However, the following query works on Postgres 12.1
>
> SELECT (ARRAY[1, 2, 3]::integer[])[1.5];
>
> array
> -------
> 2
>
> I believe a more appropriate statement would acknowledge that at least some
> values undergo an explicit-style conversion to an integer.
OK, how is the attached patch?
--
Bruce Momjian <bruce@momjian.us> https://momjian.us
EnterpriseDB https://enterprisedb.com
The usefulness of a cup is in its emptiness, Bruce Lee
Attachments:
array.diff (text/x-diff, 500B) download
diff --git a/doc/src/sgml/syntax.sgml b/doc/src/sgml/syntax.sgml
index 2f993ca2e0..4930cecd7b 100644
--- a/doc/src/sgml/syntax.sgml
+++ b/doc/src/sgml/syntax.sgml
@@ -1378,7 +1378,7 @@ CREATE FUNCTION dept(text) RETURNS dept
</synopsis>
(Here, the brackets <literal>[ ]</literal> are meant to appear literally.)
Each <replaceable>subscript</replaceable> is itself an expression,
- which must yield an integer value.
+ and will be rounded to an integer value.
</para>
<para>
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Subscript expressions do not have to evaluate to integers
2020-08-22 00:33 Re: Subscript expressions do not have to evaluate to integers Bruce Momjian <bruce@momjian.us>
@ 2020-08-22 01:22 ` Tom Lane <tgl@sss.pgh.pa.us>
2020-08-22 02:21 ` Re: Subscript expressions do not have to evaluate to integers David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: Tom Lane @ 2020-08-22 01:22 UTC (permalink / raw)
To: Bruce Momjian <bruce@momjian.us>; +Cc: sean@materialize.io; pgsql-docs@lists.postgresql.org
Bruce Momjian <bruce@momjian.us> writes:
> On Wed, Jul 22, 2020 at 02:59:18AM +0000, PG Doc comments form wrote:
>> I believe a more appropriate statement would acknowledge that at least some
>> values undergo an explicit-style conversion to an integer.
> OK, how is the attached patch?
"and" is not an improvement over "which". Otherwise seems OK.
(The proposed patch for generic subscripting will probably need to
rewrite this completely, but for now this is an improvement.)
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Subscript expressions do not have to evaluate to integers
2020-08-22 00:33 Re: Subscript expressions do not have to evaluate to integers Bruce Momjian <bruce@momjian.us>
2020-08-22 01:22 ` Re: Subscript expressions do not have to evaluate to integers Tom Lane <tgl@sss.pgh.pa.us>
@ 2020-08-22 02:21 ` David G. Johnston <david.g.johnston@gmail.com>
2020-08-22 15:47 ` Re: Subscript expressions do not have to evaluate to integers Bruce Momjian <bruce@momjian.us>
0 siblings, 1 reply; 5+ messages in thread
From: David G. Johnston @ 2020-08-22 02:21 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Bruce Momjian <bruce@momjian.us>; sean@materialize.io, Pg Docs <pgsql-docs@lists.postgresql.org>
On Fri, Aug 21, 2020 at 6:22 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Bruce Momjian <bruce@momjian.us> writes:
> > On Wed, Jul 22, 2020 at 02:59:18AM +0000, PG Doc comments form wrote:
> >> I believe a more appropriate statement would acknowledge that at least
> some
> >> values undergo an explicit-style conversion to an integer.
>
> > OK, how is the attached patch?
>
> "and" is not an improvement over "which". Otherwise seems OK.
>
> (The proposed patch for generic subscripting will probably need to
> rewrite this completely, but for now this is an improvement.)
>
I was going to add that maybe we should link to the round(dp or numeric)
function in the documentation and let it be explicit about the rounding
rules pertaining to half - which when I look isn't actually documented:
round(dp or numeric) (same as input) round to nearest integer
Maybe everyone just knows that rounding, unless otherwise stated, rounds
halves away from zero but it doesn't seem like a bad idea to be explicit.
David J.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Subscript expressions do not have to evaluate to integers
2020-08-22 00:33 Re: Subscript expressions do not have to evaluate to integers Bruce Momjian <bruce@momjian.us>
2020-08-22 01:22 ` Re: Subscript expressions do not have to evaluate to integers Tom Lane <tgl@sss.pgh.pa.us>
2020-08-22 02:21 ` Re: Subscript expressions do not have to evaluate to integers David G. Johnston <david.g.johnston@gmail.com>
@ 2020-08-22 15:47 ` Bruce Momjian <bruce@momjian.us>
2020-08-22 20:34 ` Re: Subscript expressions do not have to evaluate to integers David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: Bruce Momjian @ 2020-08-22 15:47 UTC (permalink / raw)
To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; sean@materialize.io, Pg Docs <pgsql-docs@lists.postgresql.org>
On Fri, Aug 21, 2020 at 07:21:30PM -0700, David G. Johnston wrote:
> On Fri, Aug 21, 2020 at 6:22 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Bruce Momjian <bruce@momjian.us> writes:
> > On Wed, Jul 22, 2020 at 02:59:18AM +0000, PG Doc comments form wrote:
> >> I believe a more appropriate statement would acknowledge that at least
> some
> >> values undergo an explicit-style conversion to an integer.
>
> > OK, how is the attached patch?
>
> "and" is not an improvement over "which". Otherwise seems OK.
OK, done in the attached patch.
> (The proposed patch for generic subscripting will probably need to
> rewrite this completely, but for now this is an improvement.)
>
>
> I was going to add that maybe we should link to the round(dp or numeric)
> function in the documentation and let it be explicit about the rounding rules
> pertaining to half - which when I look isn't actually documented:
>
> round(dp or numeric) (same as input) round to nearest integer
>
> Maybe everyone just knows that rounding, unless otherwise stated, rounds halves
> away from zero but it doesn't seem like a bad idea to be explicit.
I don't think we use round() directly, to I am hesitant to link to that,
but your idea that we should mention we are rounding to the "nearest"
integer, rather than floor or ceil is a good one, so I mentioned that in
the attached updated patch.
--
Bruce Momjian <bruce@momjian.us> https://momjian.us
EnterpriseDB https://enterprisedb.com
The usefulness of a cup is in its emptiness, Bruce Lee
Attachments:
array.diff (text/x-diff, 511B) download
diff --git a/doc/src/sgml/syntax.sgml b/doc/src/sgml/syntax.sgml
index 2f993ca2e0..f1e3402528 100644
--- a/doc/src/sgml/syntax.sgml
+++ b/doc/src/sgml/syntax.sgml
@@ -1378,7 +1378,7 @@ CREATE FUNCTION dept(text) RETURNS dept
</synopsis>
(Here, the brackets <literal>[ ]</literal> are meant to appear literally.)
Each <replaceable>subscript</replaceable> is itself an expression,
- which must yield an integer value.
+ which will be rounded to the nearest integer value.
</para>
<para>
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Subscript expressions do not have to evaluate to integers
2020-08-22 00:33 Re: Subscript expressions do not have to evaluate to integers Bruce Momjian <bruce@momjian.us>
2020-08-22 01:22 ` Re: Subscript expressions do not have to evaluate to integers Tom Lane <tgl@sss.pgh.pa.us>
2020-08-22 02:21 ` Re: Subscript expressions do not have to evaluate to integers David G. Johnston <david.g.johnston@gmail.com>
2020-08-22 15:47 ` Re: Subscript expressions do not have to evaluate to integers Bruce Momjian <bruce@momjian.us>
@ 2020-08-22 20:34 ` David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 0 replies; 5+ messages in thread
From: David G. Johnston @ 2020-08-22 20:34 UTC (permalink / raw)
To: Bruce Momjian <bruce@momjian.us>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; sean@materialize.io, Pg Docs <pgsql-docs@lists.postgresql.org>
On Sat, Aug 22, 2020 at 8:47 AM Bruce Momjian <bruce@momjian.us> wrote:
> On Fri, Aug 21, 2020 at 07:21:30PM -0700, David G. Johnston wrote:
> > On Fri, Aug 21, 2020 at 6:22 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> >
> > Bruce Momjian <bruce@momjian.us> writes:
> > > On Wed, Jul 22, 2020 at 02:59:18AM +0000, PG Doc comments form
> wrote:
> > >> I believe a more appropriate statement would acknowledge that at
> least
> > some
> > >> values undergo an explicit-style conversion to an integer.
> >
> > > OK, how is the attached patch?
> >
> > "and" is not an improvement over "which". Otherwise seems OK.
>
> OK, done in the attached patch.
>
Works for me.
David J.
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2020-08-22 20:34 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-08-22 00:33 Re: Subscript expressions do not have to evaluate to integers Bruce Momjian <bruce@momjian.us>
2020-08-22 01:22 ` Tom Lane <tgl@sss.pgh.pa.us>
2020-08-22 02:21 ` David G. Johnston <david.g.johnston@gmail.com>
2020-08-22 15:47 ` Bruce Momjian <bruce@momjian.us>
2020-08-22 20:34 ` David G. Johnston <david.g.johnston@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox