1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] Forward fill NULL values in multiple columns

Discussão em 'Outras Linguagens' iniciado por Stack, Outubro 1, 2024 às 07:12.

  1. Stack

    Stack Membro Participativo

    I have a table which contains some time-series data.

    time | bid | ask
    -------------------------------+--------+--------
    2018-12-27 01:04:06.978456+00 | 1.7086 |
    2018-12-27 01:04:07.006461+00 | 1.7087 |
    2018-12-27 01:04:07.021961+00 | | 1.7106
    2018-12-27 01:04:08.882591+00 | 1.7025 | 1.7156
    2018-12-27 01:04:09.374118+00 | | 1.7106
    2018-12-27 01:04:09.39018+00 | 1.7087 | 1.7156
    2018-12-27 01:04:15.793528+00 | 1.7045 |
    2018-12-27 01:04:15.833545+00 | 1.7083 |
    2018-12-27 01:04:15.893536+00 | | 1.7096
    2018-12-27 01:04:16.258062+00 | 1.7045 | 1.7095
    2018-12-27 01:04:16.653573+00 | 1.7046 | 1.7148
    2018-12-27 01:04:16.665564+00 | | 1.7097


    I would like to forward-fill over NULL values, so that the result of my query looks like this:

    time | bid | ask
    -------------------------------+--------+--------
    2018-12-27 01:04:06.978456+00 | 1.7086 |
    2018-12-27 01:04:07.006461+00 | 1.7087 |
    2018-12-27 01:04:07.021961+00 | 1.7087 | 1.7106
    2018-12-27 01:04:08.882591+00 | 1.7025 | 1.7156
    2018-12-27 01:04:09.374118+00 | 1.7025 | 1.7106
    2018-12-27 01:04:09.39018+00 | 1.7087 | 1.7156
    2018-12-27 01:04:15.793528+00 | 1.7045 | 1.7156
    2018-12-27 01:04:15.833545+00 | 1.7083 | 1.7156
    2018-12-27 01:04:15.893536+00 | 1.7083 | 1.7096
    2018-12-27 01:04:16.258062+00 | 1.7045 | 1.7095
    2018-12-27 01:04:16.653573+00 | 1.7046 | 1.7148
    2018-12-27 01:04:16.665564+00 | 1.7046 | 1.7097


    How can I achieve this?

    I am using postgresql 10, with the timescaledb extension

    Continue reading...

Compartilhe esta Página