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

Interpolated_Average Error with Multi-Day Buckets Under Daylight Savings Time Settings in Europe/Berlin Timezone #798

Open
Timsgmlr opened this issue Apr 30, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Timsgmlr
Copy link

Relevant system information:

  • OS: Ubuntu 22.04.04 LTS
  • PostgreSQL version (PostgreSQL 15.6 (Ubuntu 15.6-1.pgdg22.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 64-bit
  • TimescaleDB Toolkit version 1.18.0
  • Installation method: docker

Describe the bug
The query involving time_bucket_gapfill and interpolated_average fails when using a two (or more)-day bucket interval during the daylight saving period with the PostgreSQL session's timezone set to Europe/Berlin. It functions correctly when the timezone is set to UTC or CET, and interestingly, it also works without issue when using a one-day bucket interval under the same conditions.

To Reproduce
Steps to reproduce the behavior:

  1. Set the PostgreSQL session timezone to Europe/Berlin.
  2. Execute the following SQL query:
SET TIMEZONE = 'EUROPE/BERLIN';

WITH generated_series AS (SELECT generate_series(
                                         TIMESTAMP WITH TIME ZONE '2024-03-27 00:00:00',
                                         TIMESTAMP WITH TIME ZONE'2024-04-08 23:59:59',
                                         INTERVAL '30 second'
                                 )               AS time,
                                 random() * 1000 AS raw_value),
     timeweighted_cte AS (SELECT time_bucket_gapfill(INTERVAL '2 days', time) AS timestamp,
                                 time_weight('locf', time, raw_value)         AS time_weight_summary,
                                 locf(last(raw_value, time)::NUMERIC)         AS value
                          FROM generated_series
                          WHERE time BETWEEN TIMESTAMP WITH TIME ZONE '2024-04-01 08:36:00+00:00'
                                    AND TIMESTAMP WITH TIME ZONE '2024-04-04 22:00:00+00:00'
                          GROUP BY timestamp)
SELECT time_bucket_gapfill(INTERVAL '2 days', timestamp) AS timestamp,
       interpolated_average(
               tws := time_weight_summary,
               start := timestamp,
               duration := INTERVAL '2 days')            AS value
FROM timeweighted_cte
ORDER BY timestamp;
  1. Observe the error message: ERROR: Interval end (765327600000000) must be after last timestamp (765331170000000).

Expected behavior
The query should execute without errors, regardless of the bucket interval or the timezone setting, including during periods that observe daylight saving time.

Actual behavior
The query fails with an error message when a two-day bucket interval is used during the daylight saving period in the Europe/Berlin timezone. The issue does not occur when using a one-day bucket interval.

@Timsgmlr Timsgmlr added the bug Something isn't working label Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant