From 97957fdbaa429c7c582d4753b108cb1e23e1b28a Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Fri, 13 Oct 2023 13:01:37 +0900 Subject: Add support for AT LOCAL When converting a timestamp to/from with/without time zone, the SQL Standard specifies an AT LOCAL variant of AT TIME ZONE which uses the session's time zone. This includes three system functions able to do the work in the same way as the existing flavors for AT TIME ZONE, except that these need to be marked as stable as they depend on the session's TimeZone GUC. Bump catalog version. Author: Vik Fearing Reviewed-by: Laurenz Albe, Cary Huang, Michael Paquier Discussion: https://postgr.es/m/8e25dec4-5667-c1a5-6581-167d710c2182@postgresfriends.org --- src/backend/utils/adt/date.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/backend/utils/adt/date.c') diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c index ae0f24de2c3..c4da10d47a9 100644 --- a/src/backend/utils/adt/date.c +++ b/src/backend/utils/adt/date.c @@ -3125,3 +3125,18 @@ timetz_izone(PG_FUNCTION_ARGS) PG_RETURN_TIMETZADT_P(result); } + +/* timetz_at_local() + * + * Unlike for timestamp[tz]_at_local, the type for timetz does not flip between + * time with/without time zone, so we cannot just call the conversion function. + */ +Datum +timetz_at_local(PG_FUNCTION_ARGS) +{ + Datum time = PG_GETARG_DATUM(0); + const char *tzn = pg_get_timezone_name(session_timezone); + Datum zone = PointerGetDatum(cstring_to_text(tzn)); + + return DirectFunctionCall2(timetz_zone, zone, time); +} -- cgit v1.2.3