Fix precision handling for some COERCE_SQL_SYNTAX functions
authorMichael Paquier <michael@paquier.xyz>
Fri, 30 Dec 2022 11:47:57 +0000 (20:47 +0900)
committerMichael Paquier <michael@paquier.xyz>
Fri, 30 Dec 2022 11:47:57 +0000 (20:47 +0900)
commit7aa81c61ec8f68212570192f3088544dbfa43cb9
tree5af49de71f755bb7dd199881b6233bd3454e4e6f
parent1f605b82ba66ece8b421b10d41094dd2e3c0c48b
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/backend/utils/adt/date.c
src/backend/utils/adt/timestamp.c
src/test/regress/expected/expressions.out
src/test/regress/sql/expressions.sql