From: Peter Eisentraut <peter@eisentraut.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Change return type of EXTRACT to numeric
Date: Tue, 06 Apr 2021 05:28:55 +0000
Message-ID: <E1lTeGl-0003Bw-2g@gemulon.postgresql.org> (raw)
Change return type of EXTRACT to numeric
The previous implementation of EXTRACT mapped internally to
date_part(), which returned type double precision (since it was
implemented long before the numeric type existed). This can lead to
imprecise output in some cases, so returning numeric would be
preferrable. Changing the return type of an existing function is a
bit risky, so instead we do the following: We implement a new set of
functions, which are now called "extract", in parallel to the existing
date_part functions. They work the same way internally but use
numeric instead of float8. The EXTRACT construct is now mapped by the
parser to these new extract functions. That way, dumps of views
etc. from old versions (which would use date_part) continue to work
unchanged, but new uses will map to the new extract functions.
Additionally, the reverse compilation of EXTRACT now reproduces the
original syntax, using the new mechanism introduced in
40c24bfef92530bd846e111c1742c2a54441c62c.
The following minor changes of behavior result from the new
implementation:
- The column name from an isolated EXTRACT call is now "extract"
instead of "date_part".
- Extract from date now rejects inappropriate field names such as
HOUR. It was previously mapped internally to extract from
timestamp, so it would silently accept everything appropriate for
timestamp.
- Return values when extracting fields with possibly fractional
values, such as second and epoch, now have the full scale that the
value has internally (so, for example, '1.000000' instead of just
'1').
Reported-by: Petr Fedorov <petr.fedorov@phystech.edu>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/42b73d2d-da12-ba9f-570a-420e0cce19d9@phystech.edu
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/a2da77cdb4661826482ebf2ddba1f953bc74afe4
Modified Files
--------------
doc/src/sgml/func.sgml | 10 +-
src/backend/parser/gram.y | 2 +-
src/backend/utils/adt/date.c | 308 ++++++++++++++++--
src/backend/utils/adt/numeric.c | 61 ++++
src/backend/utils/adt/ruleutils.c | 21 ++
src/backend/utils/adt/timestamp.c | 471 ++++++++++++++++++++--------
src/include/catalog/catversion.h | 2 +-
src/include/catalog/pg_proc.dat | 18 ++
src/include/utils/numeric.h | 1 +
src/test/regress/expected/create_view.out | 2 +-
src/test/regress/expected/date.out | 452 ++++++++++++--------------
src/test/regress/expected/interval.out | 101 +++---
src/test/regress/expected/psql_crosstab.out | 12 +-
src/test/regress/expected/time.out | 48 ++-
src/test/regress/expected/timestamp.out | 91 ++++++
src/test/regress/expected/timestamptz.out | 92 ++++++
src/test/regress/expected/timetz.out | 60 +++-
src/test/regress/sql/date.sql | 22 +-
src/test/regress/sql/interval.sql | 12 +
src/test/regress/sql/time.sql | 7 +
src/test/regress/sql/timestamp.sql | 13 +
src/test/regress/sql/timestamptz.sql | 13 +
src/test/regress/sql/timetz.sql | 7 +
23 files changed, 1330 insertions(+), 496 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: peter@eisentraut.org
Subject: Re: pgsql: Change return type of EXTRACT to numeric
In-Reply-To: <E1lTeGl-0003Bw-2g@gemulon.postgresql.org>
References: <E1lTeGl-0003Bw-2g@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox