From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: abelisto@gmail.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #14446: make_date with negative year
Date: Sun, 4 Dec 2016 10:40:50 -0300
Message-ID: <20161204134050.vsfjbwub6u6jljax@alvherre.pgsql> (raw)
In-Reply-To: <20161204055939.4361.33460@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
abelisto@gmail.com wrote:
> Bug reference: 14446
> Logged by: Andy Abelisto
> Email address: abelisto@gmail.com
> PostgreSQL version: 9.5.5
> Operating system: Linux Mint
> Description:
>
> with t(x) as (values('1111-11-11 BC'::date)) select make_date(extract(year
> from x)::int, extract(month from x)::int, extract(day from x)::int) from
> t;
> ERROR: date field value out of range: -1111-11-11
make_date() has:
/*
* Note: we'll reject zero or negative year values. Perhaps negatives
* should be allowed to represent BC years?
*/
dterr = ValidateDate(DTK_DATE_M, false, false, false, &tm);
With the attached patch it becomes (needs docs, tests):
with t(x) as (values('1111-11-11 BC'::date),
('00001-11-11 bc'),
('00001-11-11'),
('1111-11-11')
)
select make_date(extract(year
from x)::int, extract(month from x)::int, extract(day from x)::int) from
t;
make_date
───────────────
1111-11-11 BC
0001-11-11 BC
0001-11-11
1111-11-11
(4 filas)
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:make_date_bc.patch (text/plain, 801B) downloaddiff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.cindex bc7d190..149991e 100644--- a/src/backend/utils/adt/date.c+++ b/src/backend/utils/adt/date.c@@ -252,16 +252,20 @@ make_date(PG_FUNCTION_ARGS)
struct pg_tm tm;
DateADT date;
int dterr;
+ bool bc = false;
tm.tm_year = PG_GETARG_INT32(0);
tm.tm_mon = PG_GETARG_INT32(1);
tm.tm_mday = PG_GETARG_INT32(2);
- /*- * Note: we'll reject zero or negative year values. Perhaps negatives- * should be allowed to represent BC years?- */- dterr = ValidateDate(DTK_DATE_M, false, false, false, &tm);+ /* Handle negative years as BC */+ if (tm.tm_year < 0)+ {+ bc = true;+ tm.tm_year = -tm.tm_year;+ }++ dterr = ValidateDate(DTK_DATE_M, false, false, bc, &tm);
if (dterr != 0)
ereport(ERROR,
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-bugs@postgresql.org
Cc: alvherre@2ndquadrant.com, abelisto@gmail.com
Subject: Re: BUG #14446: make_date with negative year
In-Reply-To: <20161204134050.vsfjbwub6u6jljax@alvherre.pgsql>
References: <20161204055939.4361.33460@wrigleys.postgresql.org> <20161204134050.vsfjbwub6u6jljax@alvherre.pgsql>
* 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