Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

access to previous/next row values #51

Open
mfulton26 opened this issue Jan 7, 2025 · 4 comments
Open

access to previous/next row values #51

mfulton26 opened this issue Jan 7, 2025 · 4 comments

Comments

@mfulton26
Copy link

I'd like a way to compute the difference between a value in a column with the previous or next value over a partition. I believe several SQL solutions use LEAD() and LAG() functions but there may be other/better ways to do it.

@mfulton26
Copy link
Author

A way to access other rows via user defined functions could be helpful too.

@Ownerbusinessjjfm
Copy link

I'd like a way to compute the difference between a value in a column with the previous or next value over a partition. I believe several SQL solutions use LEAD() and LAG() functions but there may be other/better ways to do it.

How and what should it be done

@mfulton26
Copy link
Author

Example using window functions:

select year, 
       month,
       fixes,
       fixes - lag(fixes) over (order by year, month) as increase,
from the_table;

source: https://stackoverflow.com/questions/24691462/postgresql-calculate-difference-between-rows

References:

@mechatroner
Copy link
Owner

Thank you for the feedback! I agree it would be cool to support window functions including lag but I haven't yet even started looking into how hard it would be to add them because I suspect it is a complex change. But IMO it is doable so when I have more time I will look into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants