1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-31 22:04:40 +03:00

Declare lead() and lag() using anycompatible not anyelement.

This allows use of a "default" expression that doesn't slavishly
match the data column's type.  Formerly you got something like
"function lag(numeric, integer, integer) does not exist", which
is not just unhelpful but actively misleading.

The SQL spec suggests that the default should be coerced to the data
column's type, but this implementation instead chooses the common
supertype, which seems at least as reasonable.

(Note: I took the opportunity to run "make reformat-dat-files" on
pg_proc.dat, so this commit includes some cosmetic changes to
recently-added entries that aren't related to lead/lag.)

Vik Fearing

Discussion: https://postgr.es/m/77675130-89da-dab1-51dd-492c93dcf5d1@postgresfriends.org
This commit is contained in:
Tom Lane
2020-11-04 15:08:37 -05:00
parent 40c24bfef9
commit 5c292e6b90
5 changed files with 58 additions and 24 deletions

View File

@ -19594,17 +19594,17 @@ SELECT count(*) FROM sometable;
<indexterm>
<primary>lag</primary>
</indexterm>
<function>lag</function> ( <parameter>value</parameter> <type>anyelement</type>
<function>lag</function> ( <parameter>value</parameter> <type>anycompatible</type>
<optional>, <parameter>offset</parameter> <type>integer</type>
<optional>, <parameter>default</parameter> <type>anyelement</type> </optional></optional> )
<returnvalue>anyelement</returnvalue>
<optional>, <parameter>default</parameter> <type>anycompatible</type> </optional></optional> )
<returnvalue>anycompatible</returnvalue>
</para>
<para>
Returns <parameter>value</parameter> evaluated at
the row that is <parameter>offset</parameter>
rows before the current row within the partition; if there is no such
row, instead returns <parameter>default</parameter>
(which must be of the same type as
(which must be of a type compatible with
<parameter>value</parameter>).
Both <parameter>offset</parameter> and
<parameter>default</parameter> are evaluated
@ -19619,17 +19619,17 @@ SELECT count(*) FROM sometable;
<indexterm>
<primary>lead</primary>
</indexterm>
<function>lead</function> ( <parameter>value</parameter> <type>anyelement</type>
<function>lead</function> ( <parameter>value</parameter> <type>anycompatible</type>
<optional>, <parameter>offset</parameter> <type>integer</type>
<optional>, <parameter>default</parameter> <type>anyelement</type> </optional></optional> )
<returnvalue>anyelement</returnvalue>
<optional>, <parameter>default</parameter> <type>anycompatible</type> </optional></optional> )
<returnvalue>anycompatible</returnvalue>
</para>
<para>
Returns <parameter>value</parameter> evaluated at
the row that is <parameter>offset</parameter>
rows after the current row within the partition; if there is no such
row, instead returns <parameter>default</parameter>
(which must be of the same type as
(which must be of a type compatible with
<parameter>value</parameter>).
Both <parameter>offset</parameter> and
<parameter>default</parameter> are evaluated