pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #14446: make_date with negative year
7+ messages / 3 participants
[nested] [flat]
* BUG #14446: make_date with negative year
@ 2016-12-04 05:59 abelisto@gmail.com
0 siblings, 1 reply; 7+ messages in thread
From: abelisto@gmail.com @ 2016-12-04 05:59 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
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
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #14446: make_date with negative year
@ 2016-12-04 13:40 Alvaro Herrera <alvherre@2ndquadrant.com>
parent: abelisto@gmail.com
0 siblings, 1 reply; 7+ messages in thread
From: Alvaro Herrera @ 2016-12-04 13:40 UTC (permalink / raw)
To: abelisto@gmail.com; +Cc: pgsql-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-bugs
Attachments:
make_date_bc.patch (text/plain, 801B) download
diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c
index 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,
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #14446: make_date with negative year
@ 2016-12-04 18:19 Pavel Stehule <pavel.stehule@gmail.com>
parent: Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 1 reply; 7+ messages in thread
From: Pavel Stehule @ 2016-12-04 18:19 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: pgsql-bugs
2016-12-04 14:40 GMT+01:00 Alvaro Herrera <alvherre@2ndquadrant.com>:
> 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)
>
>
+1
Regards
Pavel
> --
> Á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-bugs
>
>
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #14446: make_date with negative year
@ 2016-12-05 18:38 Alvaro Herrera <alvherre@2ndquadrant.com>
parent: Pavel Stehule <pavel.stehule@gmail.com>
0 siblings, 1 reply; 7+ messages in thread
From: Alvaro Herrera @ 2016-12-05 18:38 UTC (permalink / raw)
To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: pgsql-bugs
Pavel Stehule wrote:
> 2016-12-04 14:40 GMT+01:00 Alvaro Herrera <alvherre@2ndquadrant.com>:
> > abelisto@gmail.com wrote:
> > >
> > > 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
So make_date was introduced in 9.4 by commit f901bb50e; this report is
based on 9.5. Do we want to backpatch this change? Since the fix only
changes behavior that currently errors out anyway, we would not be
changing anything that people are relying on. I lean towards
backpatching all the way back to 9.4 myself.
--
Á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-bugs
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #14446: make_date with negative year
@ 2016-12-05 18:57 Pavel Stehule <pavel.stehule@gmail.com>
parent: Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 1 reply; 7+ messages in thread
From: Pavel Stehule @ 2016-12-05 18:57 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: ND Abelisto <abelisto@gmail.com>; pgsql-bugs
2016-12-05 19:38 GMT+01:00 Alvaro Herrera <alvherre@2ndquadrant.com>:
> Pavel Stehule wrote:
> > 2016-12-04 14:40 GMT+01:00 Alvaro Herrera <alvherre@2ndquadrant.com>:
>
> > > abelisto@gmail.com wrote:
> > > >
> > > > 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
>
> So make_date was introduced in 9.4 by commit f901bb50e; this report is
> based on 9.5. Do we want to backpatch this change? Since the fix only
> changes behavior that currently errors out anyway, we would not be
> changing anything that people are relying on. I lean towards
> backpatching all the way back to 9.4 myself.
>
I have not a problem with backpatch - there are a user who see current
behave as bug.
Regards
Pavel
>
> --
> Álvaro Herrera https://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #14446: make_date with negative year
@ 2017-01-18 21:58 Alvaro Herrera <alvherre@2ndquadrant.com>
parent: Pavel Stehule <pavel.stehule@gmail.com>
0 siblings, 1 reply; 7+ messages in thread
From: Alvaro Herrera @ 2017-01-18 21:58 UTC (permalink / raw)
To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: ND Abelisto <abelisto@gmail.com>; pgsql-bugs
Pavel Stehule wrote:
> 2016-12-05 19:38 GMT+01:00 Alvaro Herrera <alvherre@2ndquadrant.com>:
> > So make_date was introduced in 9.4 by commit f901bb50e; this report is
> > based on 9.5. Do we want to backpatch this change? Since the fix only
> > changes behavior that currently errors out anyway, we would not be
> > changing anything that people are relying on. I lean towards
> > backpatching all the way back to 9.4 myself.
>
> I have not a problem with backpatch - there are a user who see current
> behave as bug.
In the end, I decided against backpatching. It is not entirely out of
the question that somebody *is* depending on this erroring out if
negative years are passed. But I am acting on my own opinion only; if
there are more votes for a backpatch, I am open to changing it.
If not, we're done here and I'd like to move along.
--
Á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-bugs
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #14446: make_date with negative year
@ 2017-01-19 04:47 Pavel Stehule <pavel.stehule@gmail.com>
parent: Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 0 replies; 7+ messages in thread
From: Pavel Stehule @ 2017-01-19 04:47 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: ND Abelisto <abelisto@gmail.com>; pgsql-bugs
2017-01-18 22:58 GMT+01:00 Alvaro Herrera <alvherre@2ndquadrant.com>:
> Pavel Stehule wrote:
> > 2016-12-05 19:38 GMT+01:00 Alvaro Herrera <alvherre@2ndquadrant.com>:
>
> > > So make_date was introduced in 9.4 by commit f901bb50e; this report is
> > > based on 9.5. Do we want to backpatch this change? Since the fix only
> > > changes behavior that currently errors out anyway, we would not be
> > > changing anything that people are relying on. I lean towards
> > > backpatching all the way back to 9.4 myself.
> >
> > I have not a problem with backpatch - there are a user who see current
> > behave as bug.
>
> In the end, I decided against backpatching. It is not entirely out of
> the question that somebody *is* depending on this erroring out if
> negative years are passed. But I am acting on my own opinion only; if
> there are more votes for a backpatch, I am open to changing it.
>
> If not, we're done here and I'd like to move along.
>
+1
Pavel
>
> --
> Álvaro Herrera https://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2017-01-19 04:47 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-12-04 05:59 BUG #14446: make_date with negative year abelisto@gmail.com
2016-12-04 13:40 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2016-12-04 18:19 ` Pavel Stehule <pavel.stehule@gmail.com>
2016-12-05 18:38 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2016-12-05 18:57 ` Pavel Stehule <pavel.stehule@gmail.com>
2017-01-18 21:58 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2017-01-19 04:47 ` Pavel Stehule <pavel.stehule@gmail.com>
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