Iterating through PostgreSQL records. How to reference data from next row?
I'm new to PostgreSQL and writing functions here is tough as nails. So I'm hoping someone can help let me know how to do what I'm trying to do. I have a table of stock prices and dates. I want to calculate the percent change from the previous day for each entry. For the earliest day of data, there won't be a previous day, so that entry can simply be Nil. Can someone look over my function and help me with a) how to reference data from the next row and b) help me clean it up? I'm aware that the WITH statement is probably not supposed to be above the IF statement. However logically, this is how I