Re: lag(bigint,int,int), etc?

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: "Colin 't Hart" <colinthart(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: lag(bigint,int,int), etc?
Date: 2017-06-27 15:06:15
Message-ID: CAHyXU0x-0_j2UvhXtjUdausJev6vBUJNy90j+MoMa20RrBFB_g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Jun 27, 2017 at 10:01 AM, Colin 't Hart <colinthart(at)gmail(dot)com> wrote:
> Hi,
>
> The following rather contrived example illustrates that lag(), lead()
> (and probably other functions) can't automatically cast an integer to
> a bigint:
>
> select lag(sum,1,0) over () from (select sum(generate_series) over
> (order by generate_series) from generate_series(1,10)) x;
> ERROR: function lag(bigint, integer, integer) does not exist
> LINE 1: select lag(sum,1,0) over () from (select sum(generate_series...
> ^
> HINT: No function matches the given name and argument types. You
> might need to add explicit type casts.
>
>
> I guess this is because the lag() and lead() functions take any type,
> and hence the default must be of the same type.
> This had me stumped for a few while until I realised that the types
> were different.
>
> Would there be any way to implement an automatic conversion?
>
> On the off-chance that this is actually a bug, this is on 9.6.3, but
> it also occurs on 9.3.17

Why not cast the arguments? The first and the third argument have to
be the same, and the second argument is always int.

merlin

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Colin 't Hart 2017-06-27 15:12:14 Re: lag(bigint,int,int), etc?
Previous Message Colin 't Hart 2017-06-27 15:01:07 lag(bigint,int,int), etc?