aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2017-01-19 09:45:38 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2017-01-19 09:45:38 -0300
commit30bcebbdcf23eb8b78e553c4b3b5eb847410ef19 (patch)
tree4e9cdf2bd1ef08f2416bb4bb07b6284b570d5147 /src/backend
parent8b07aee8c5d803801c00103f0d61e32356aaf29c (diff)
downloadpostgresql-30bcebbdcf23eb8b78e553c4b3b5eb847410ef19.tar.gz
postgresql-30bcebbdcf23eb8b78e553c4b3b5eb847410ef19.zip
Allow negative years in make_date to represent BC years
There doesn't seem to be any reason not to allow negative years to be interpreted as BC, so do that. The documentation is pretty vague on the details of this function, so nothing needs to change there. Reported-by: Andy Abelisto, in bug #14446
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/utils/adt/date.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c
index 96cfacdf30f..0a100a30eaf 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,