From 7aa81c61ec8f68212570192f3088544dbfa43cb9 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Fri, 30 Dec 2022 20:47:57 +0900 Subject: Fix precision handling for some COERCE_SQL_SYNTAX functions f193883 has been incorrectly setting up the precision used in the timestamp compilations returned by the following functions: - LOCALTIME - LOCALTIMESTAMP - CURRENT_TIME - CURRENT_TIMESTAMP Specifying an out-of-range precision for CURRENT_TIMESTAMP and LOCALTIMESTAMP was raising a WARNING without adjusting the precision, leading to a subsequent error. LOCALTIME and CURRENT_TIME raised a WARNING without an error, still the precision given to the internal routines was not correct, so let's be clean. Ian has reported the problems in timestamp.c, while I have noticed the ones in date.c. Regression tests are added for all of them with precisions high enough to provide coverage for the warnings, something that went missing up to this commit. Author: Ian Lawrence Barwick, Michael Paquier Discussion: https://postgr.es/m/CAB8KJ=jQEnn9sYG+N752spt68wMrhmT-ocHCh4oeNmHF82QMWA@mail.gmail.com --- src/test/regress/sql/expressions.sql | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/test/regress/sql') diff --git a/src/test/regress/sql/expressions.sql b/src/test/regress/sql/expressions.sql index f9a0299d17..fea5358d25 100644 --- a/src/test/regress/sql/expressions.sql +++ b/src/test/regress/sql/expressions.sql @@ -17,12 +17,17 @@ SELECT now()::timetz(4)::text = current_time(4)::text; SELECT now()::time::text = localtime::text; SELECT now()::time(3)::text = localtime(3)::text; --- current_timestamp / localtimestamp (always matches because of transactional behaviour) +-- current_time[stamp]/ localtime[stamp] (always matches because of transactional behaviour) SELECT current_timestamp = NOW(); -- precision SELECT length(current_timestamp::text) >= length(current_timestamp(0)::text); -- localtimestamp SELECT now()::timestamp::text = localtimestamp::text; +-- precision overflow +SELECT current_time = current_time(7); +SELECT current_timestamp = current_timestamp(7); +SELECT localtime = localtime(7); +SELECT localtimestamp = localtimestamp(7); -- current_role/user/user is tested in rolnames.sql -- cgit v1.2.1