-
Notifications
You must be signed in to change notification settings - Fork 882
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
[Bug]: time_bucket_gapfill only handles time zone correctly if it is equal to the DB time zone #5334
Comments
Thank you @maxhertrampf for reaching out!
I think with this description if the last observation was Do you want to get the last value only iff the last was not null? You could try something like this (this involves windowing for showcase):
I think this be the sideeffect of the 1. issue. I'll put this issue in the |
@kgyrtkirk , thank you for analysing the problem.
For example, the following SQL ... set timezone = 'UTC';
SELECT time_bucket(INTERVAL '1 mons', time, timezone => 'Europe/Berlin') AS "month",
avg(value) as avg
FROM metrics rd
WHERE device_id = 1 AND time >= '2022-01-01T00:00:00+01:00' AND time < '2024-01-01T00:00:00+01:00'
GROUP BY month
ORDER BY month
LIMIT 1001; ... correctly returns:
The only "problem" here is that the timestamps are formatted in the UTC time zone, but they are correct. For us, that is not a real problem. With
|
oh - you are right!
I was not comparing them that closely but I think we should propably re-check 2. again after 1. will be fixed - because it seems like gapfill have failed to pickup the |
Hi, I have the same or similar issue (for my description see timescale/timescaledb-toolkit#746) and was wondering if there is an estimate for when this could be resolved? |
Hi @antekresic! I think your PR #6155 fixes this issue as well. |
Yes, that's correct. This has been fixed in the recent 2.12.2 release. I'm closing this ticket as fixed, feel free to reopen it if you have any other concerns. |
@antekresic + @lkshminarayanan I don't believe this is fixed. I'm currently on timescale 2.12.2 and postgres 14.9, and using the following SQL and SHOW timezone; -- UTC
CREATE TABLE metrics
(
time TIMESTAMP WITH TIME ZONE,
value DOUBLE PRECISION
);
INSERT INTO metrics
VALUES ('2023-11-05T00:00:00+01:00', 2),
('2023-11-06T00:00:00+01:00', 3),
('2023-11-07T00:00:00+01:00', 3),
('2023-11-08T00:00:00+01:00', 3),
('2023-11-09T00:00:00+01:00', 3.3);
SELECT avg(m.value), time_bucket_gapfill('1 day',m.time,'America/Denver') as day_bucket
FROM metrics m
WHERE m.time > (now()) - interval '29 days'
AND m.time < (now())
GROUP BY day_bucket; Results (33 rows):
And I, too, can set the local timezone and get the correct results: begin;
SET LOCAL time zone 'America/Denver';
SELECT avg(m.value), time_bucket_gapfill('1 day',m.time,'America/Denver') as day_bucket
FROM metrics m
WHERE m.time > (now()) - interval '29 days'
AND m.time < (now())
GROUP BY day_bucket;
commit; Results (30 rows)
Let me know if you'd like me to move this to a new issue, or keep the discussion here. Thanks! |
I think #6507 addresses the remaining problems |
What type of bug is this?
Incorrect result
What subsystems and features are affected?
Gapfill
What happened?
Since TimescaleDB version 2.9.0, time_bucket_gapfill can handle time zones with the additional
timezone
parameter.However, when the database's time zone is not equal to the
timezone
parameter, the function produces wrong results. The timestamps, the filled gaps, and even the number of results are incorrect (see below).This happens when aggregating over a longer period (e.g. two years) in monthly intervals.
It does not occur in some other cases with fewer values and a shorter interval.
A workaround is to set the time zone for the transaction to the same one as the one used for the gapfilling, e.g. via
set local timezone = 'Europe/Berlin'
, but this should not be necessary.TimescaleDB version affected
2.9.1
PostgreSQL version used
14.6
What operating system did you use?
Ubuntu 22.04.1 LTS
What installation method did you use?
Docker
What platform did you run on?
On prem/Self-hosted
Relevant log output and stack trace
No response
How can we reproduce the bug?
The following creates a table
metrics
with a few rows and then tries to fill gaps in monthly buckets and a time range of two years.The result is the following:
As you can see, the results are wrong:
2
3
and3.3
) are just added rawNow, if I change the DB's time zone to German time via
set timezone TO 'Europe/Berlin'
, the same query returns the correct results:The text was updated successfully, but these errors were encountered: