1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-13 07:41:39 +03:00

Avoid some table rewrites for ALTER TABLE .. SET DATA TYPE timestamp.

When the timezone is UTC, timestamptz and timestamp are binary coercible
in both directions.  See b8a18ad485 and
c22ecc6562 for the previous attempt in
this problem space.  Skip the table rewrite; for now, continue to
needlessly rewrite any index on an affected column.

Reviewed by Simon Riggs and Tom Lane.

Discussion: https://postgr.es/m/20190226061450.GA1665944@rfd.leadboat.com
This commit is contained in:
Noah Misch
2019-03-08 20:16:27 -08:00
parent 82a5649fb9
commit 3c5926301a
5 changed files with 65 additions and 7 deletions

View File

@ -5168,6 +5168,23 @@ timestamp_izone(PG_FUNCTION_ARGS)
PG_RETURN_TIMESTAMPTZ(result);
} /* timestamp_izone() */
/* TimestampTimestampTzRequiresRewrite()
*
* Returns false if the TimeZone GUC setting causes timestamp_timestamptz and
* timestamptz_timestamp to be no-ops, where the return value has the same
* bits as the argument. Since project convention is to assume a GUC changes
* no more often than STABLE functions change, the answer is valid that long.
*/
bool
TimestampTimestampTzRequiresRewrite(void)
{
long offset;
if (pg_get_timezone_offset(session_timezone, &offset) && offset == 0)
PG_RETURN_BOOL(false);
PG_RETURN_BOOL(true);
}
/* timestamp_timestamptz()
* Convert local timestamp to timestamp at GMT
*/