0

I want to select a day in my timezone for example:

from the 2021-09-09 00:00 +02 to 2021-09-10 00:00 +02. But the following code:

set timezone TO 'Europe/Berlin';
SELECT TIMESTAMP::timestamptz,sensor_id,value
FROM my_table
WHERE sensor_id IN (1,2,3)
AND TIMESTAMP > '2021-09-09' AND TIMESTAMP < '2021-09-10' 
ORDER BY TIMESTAMP

gives me the right values but with wrong timezone for example first rows are:

timestamp,sensor_id,value
2021-09-09 02:00 +02,1,21
2021-09-09 02:00 +02,2,34
2021-09-09 02:00 +02,3,54

but should be 2021-09-09 00:00 +02 or 2021-09-08 22:00 +00

The problem is bigger when the difference with utc changes between winter and summer

Anybony can help me?

PostgreSQL v.12

1 Answer 1

1
SELECT TIMESTAMP::timestamptz AT TIME ZONE 'CETDST',sensor_id,value
FROM my_table
WHERE sensor_id IN (1,2,3)
AND TIMESTAMP AT TIME ZONE 'CETDST' > '2021-09-09'
AND TIMESTAMP AT TIME ZONE 'CETDST' < '2021-09-10' 
ORDER BY TIMESTAMP
Sign up to request clarification or add additional context in comments.

9 Comments

Whoops sorry. You can try "CETDST" (Central European Daylight Savings Time). I am not 100% sure if it does, but i thinks it observes wether it's summer or winter time.
write the full query because looking deeper doesn't seem to work (AT TIME ZONE has to be written after timestamptz)
SELECT TIMESTAMP::timestamptz AT TIME ZONE "CETDST",sensor_id,value FROM my_table WHERE sensor_id IN (1,2,3) AND timestamptz > '2021-09-09' AND timestamptz < '2021-09-10' ORDER BY timestamptz
Sorry, nevermind. I thoght "TIMESTAMP" was the type of the column. Let me take another look.
I have edited the code above.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.