Reputation: 33
I'm trying to select a double precision (floating) value from a previous line of a table in PostgreSQL, but the lag() function is only working if the chosen column is an integer:
This code gives the error:
"ERROR: function lag(double precision, integer, integer) does not exist"
select id_client, date, value, lag(value, 1, 0) over (order by date)
This code works fine but i loose the decimals :
select id_client, date, value, lag(cast(value as int), 1, 0) over (order by date)
Upvotes: 3
Views: 2741
Reputation: 2322
your default in lag function must be of the same type as main value:
lag(value, 1, 0::double precision)
then it works
Upvotes: 6
Reputation: 1385
Try like this:
select id_client, date, value, lag(value) over (order by date)
Upvotes: 0