Skip to content

Commit 405a753

Browse files
committed
Make datetime bucket seeding independent of SET TIMEZONE =
1 parent 4450097 commit 405a753

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/query/anonymization.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,9 @@ static hash_t hash_label(Oid type, Datum value, bool is_null)
632632
if (TypeCategory(type) == TYPCATEGORY_DATETIME)
633633
{
634634
char value_as_string[MAXDATELEN + 1];
635-
/* Leveraging `json.h` as a way to get style-stable encoding of various datetime types. */
636-
JsonEncodeDateTime(value_as_string, value, type, NULL);
635+
/* Leveraging `json.h` with UTC to get style-stable encoding of various datetime types. */
636+
const int tzp = 0;
637+
JsonEncodeDateTime(value_as_string, value, type, &tzp);
637638
return hash_string(value_as_string);
638639
}
639640

test/expected/datetime.out

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,17 @@ SELECT ts, count(*) FROM test_datetime GROUP BY 1;
4545
2012-05-14 00:00:00 | 9
4646
(1 row)
4747

48+
SET TIMEZONE TO 'UTC';
49+
SELECT tz, count(*) FROM test_datetime GROUP BY 1;
50+
tz | count
51+
------------------------+-------
52+
2012-05-14 07:00:00+00 | 11
53+
(1 row)
54+
55+
SET TIMEZONE TO DEFAULT;
56+
SELECT tz, count(*) FROM test_datetime GROUP BY 1;
57+
tz | count
58+
------------------------+-------
59+
2012-05-14 00:00:00-07 | 11
60+
(1 row)
61+

test/sql/datetime.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ SET datestyle = 'SQL';
3838
SELECT ts, count(*) FROM test_datetime GROUP BY 1;
3939
SET datestyle = 'ISO';
4040
SELECT ts, count(*) FROM test_datetime GROUP BY 1;
41+
42+
SET TIMEZONE TO 'UTC';
43+
SELECT tz, count(*) FROM test_datetime GROUP BY 1;
44+
SET TIMEZONE TO DEFAULT;
45+
SELECT tz, count(*) FROM test_datetime GROUP BY 1;

0 commit comments

Comments
 (0)