Last active
May 13, 2020 16:52
-
-
Save erikdubbelboer/1e1b8679a385923892a0f4d6f7e916b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE test (timestamp DateTime, i UInt8) Engine=MergeTree() PARTITION BY toYYYYMM(timestamp) ORDER BY (i); | |
INSERT INTO test values ('2020-05-13 16:38:45', 1); | |
SELECT | |
toTimeZone(timestamp, 'America/Sao_Paulo') AS converted, | |
timestamp AS original | |
FROM test | |
LEFT JOIN (SELECT 2 AS x) AS anything ON x = i | |
WHERE timestamp >= toDateTime('2020-05-13T00:00:00', 'America/Sao_Paulo'); | |
/* | |
┌─converted───────────┬─original────────────┐ | |
│ 2020-05-13 16:38:45 │ 2020-05-13 16:38:45 │ <-- toTimeZone is ignored. | |
└─────────────────────┴─────────────────────┘ | |
*/ | |
SELECT | |
toTimeZone(timestamp, 'America/Sao_Paulo') AS converted, | |
timestamp AS original | |
FROM test | |
-- LEFT JOIN (SELECT 2 AS x) AS anything ON x = i -- Removing the join fixes the issue. | |
WHERE timestamp >= toDateTime('2020-05-13T00:00:00', 'America/Sao_Paulo'); | |
/* | |
┌─converted───────────┬─original────────────┐ | |
│ 2020-05-13 13:38:45 │ 2020-05-13 16:38:45 │ <-- toTimeZone works. | |
└─────────────────────┴─────────────────────┘ | |
*/ | |
SELECT | |
toTimeZone(timestamp, 'America/Sao_Paulo') AS converted, | |
timestamp AS original | |
FROM test | |
LEFT JOIN (SELECT 2 AS x) AS anything ON x = i | |
WHERE timestamp >= '2020-05-13T00:00:00'; -- Not using toDateTime in the WHERE also fixes the issue. | |
/* | |
┌─converted───────────┬─original────────────┐ | |
│ 2020-05-13 13:38:45 │ 2020-05-13 16:38:45 │ | |
└─────────────────────┴─────────────────────┘ | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment