mirror of
https://github.com/postgres/postgres.git
synced 2025-11-22 12:22:45 +03:00
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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -10347,6 +10347,16 @@ get_func_sql_syntax(FuncExpr *expr, deparse_context *context)
|
||||
appendStringInfoChar(buf, ')');
|
||||
return true;
|
||||
|
||||
case F_TIMEZONE_TIMESTAMP:
|
||||
case F_TIMEZONE_TIMESTAMPTZ:
|
||||
case F_TIMEZONE_TIMETZ:
|
||||
/* AT LOCAL */
|
||||
appendStringInfoChar(buf, '(');
|
||||
get_rule_expr_paren((Node *) linitial(expr->args), context, false,
|
||||
(Node *) expr);
|
||||
appendStringInfoString(buf, " AT LOCAL)");
|
||||
return true;
|
||||
|
||||
case F_OVERLAPS_TIMESTAMPTZ_INTERVAL_TIMESTAMPTZ_INTERVAL:
|
||||
case F_OVERLAPS_TIMESTAMPTZ_INTERVAL_TIMESTAMPTZ_TIMESTAMPTZ:
|
||||
case F_OVERLAPS_TIMESTAMPTZ_TIMESTAMPTZ_TIMESTAMPTZ_INTERVAL:
|
||||
|
||||
@@ -5921,3 +5921,23 @@ generate_series_timestamptz_at_zone(PG_FUNCTION_ARGS)
|
||||
{
|
||||
return generate_series_timestamptz_internal(fcinfo);
|
||||
}
|
||||
|
||||
/* timestamp_at_local()
|
||||
* timestamptz_at_local()
|
||||
*
|
||||
* The regression tests do not like two functions with the same proargs and
|
||||
* prosrc but different proname, but the grammar for AT LOCAL needs an
|
||||
* overloaded name to handle both types of timestamp, so we make simple
|
||||
* wrappers for it.
|
||||
*/
|
||||
Datum
|
||||
timestamp_at_local(PG_FUNCTION_ARGS)
|
||||
{
|
||||
return timestamp_timestamptz(fcinfo);
|
||||
}
|
||||
|
||||
Datum
|
||||
timestamptz_at_local(PG_FUNCTION_ARGS)
|
||||
{
|
||||
return timestamptz_timestamp(fcinfo);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user