Skip to content

Commit

Permalink
Force DateStyle and DateOrder in materialization
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziomello committed Oct 7, 2024
1 parent bfc3041 commit 2d01fb0
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions tsl/src/continuous_aggs/materialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 2d01fb0

Please sign in to comment.