I have the following table (with different currencies):
| date | currency | ex_rate |
|---|---|---|
| 30/11/2020 00.00 | USD | 0.8347245409015025 |
| 27/11/2020 00.00 | USD | 0.8387854386847845 |
| 26/11/2020 00.00 | USD | 0.84033613445378152 |
As you can see, there is some missing data for two dates. I would like to fill it with the previous available date, so it would be like this:
| date | currency | ex_rate |
|---|---|---|
| 30/11/2020 00.00 | USD | 0.8347245409015025 |
| 29/11/2020 00.00 | USD | 0.8387854386847845 |
| 28/11/2020 00.00 | USD | 0.8387854386847845 |
| 27/11/2020 00.00 | USD | 0.8387854386847845 |
| 26/11/2020 00.00 | USD | 0.84033613445378152 |
Or redirect me to a question of the same kind
You can use
generate_seriesto build the series of dates from the earlierst and later values available in the table, then bring the corresponding rows with a lateral join:I wonder whether a
left joinon date equality and then some window function technique to build groups of records might be more efficient:Note that this can easily be generalized to handle all currencies at once: