From 2d01fb0a4df0590c2d685ac1c2f92f200fa19434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabr=C3=ADzio=20de=20Royes=20Mello?= Date: Mon, 7 Oct 2024 10:17:57 -0300 Subject: [PATCH] Force DateStyle and DateOrder in materialization --- tsl/src/continuous_aggs/materialize.c | 39 +++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/tsl/src/continuous_aggs/materialize.c b/tsl/src/continuous_aggs/materialize.c index 9bee509adff..b1cd3c8c22c 100644 --- a/tsl/src/continuous_aggs/materialize.c +++ b/tsl/src/continuous_aggs/materialize.c @@ -369,22 +369,51 @@ spi_update_watermark(Hypertable *mat_ht, SchemaAndName materialization_table, } } +static char * +OidSafeTimestampTzOutputFunctionCall(Oid type, Datum val) +{ + char *result; + int SavedDateStyle, SavedDateOrder; + Oid functionId; + bool type_is_varlena; + + /* Save DateStyle and DateOrder and force it to use ISO dates and YMD order */ + if (type == TIMESTAMPTZOID) + { + SavedDateStyle = DateStyle; + SavedDateOrder = DateOrder; + DateStyle = USE_ISO_DATES; + DateOrder = DATEORDER_YMD; + } + + getTypeOutputInfo(type, &functionId, &type_is_varlena); + result = OidOutputFunctionCall(functionId, val); + + /* Restore previous date style and order configuration */ + if (type == TIMESTAMPTZOID) + { + DateStyle = SavedDateStyle; + DateOrder = SavedDateOrder; + } + + return result; +} + static void spi_update_materializations(Hypertable *mat_ht, const ContinuousAgg *cagg, SchemaAndName partial_view, SchemaAndName materialization_table, const NameData *time_column_name, TimeRange invalidation_range, const int32 chunk_id) { - Oid out_fn; - bool type_is_varlena; char *invalidation_start; char *invalidation_end; StringInfo chunk_condition = makeStringInfo(); uint64 rows_processed = 0; - getTypeOutputInfo(invalidation_range.type, &out_fn, &type_is_varlena); - invalidation_start = OidOutputFunctionCall(out_fn, invalidation_range.start); - invalidation_end = OidOutputFunctionCall(out_fn, invalidation_range.end); + invalidation_start = + OidSafeTimestampTzOutputFunctionCall(invalidation_range.type, invalidation_range.start); + invalidation_end = + OidSafeTimestampTzOutputFunctionCall(invalidation_range.type, invalidation_range.end); /* MERGE statement is available starting on PG15 and we'll support it only in the new format of * CAggs and for non-compressed hypertables */