Re: proposal: simple date constructor from numeric values

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Jeevan Chalke <jeevan(dot)chalke(at)enterprisedb(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Brendan Jurd <direvus(at)gmail(dot)com>
Subject: Re: proposal: simple date constructor from numeric values
Date: 2013-10-11 21:37:45
Message-ID: 20131011213745.GA9746@eldon.alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Pavel Stehule escribió:

> It was my mistake - I was confused from timestamp with time zone type,
> what has zero related to date and time.
>
> fixed to immutable,
> fixed duplicate oid

Thanks. I wasn't sure about the error message returned when times are
outside range; how about this instead? I'm not wedded to this approach
-- I can return to yours if this one isn't liked -- but I think the
more specific messages are better. I realize this is inconsistent with
the make_date case which always displays the full date instead of
specific fields, but I think it's more likely that someone is doing
arithmetic to enter time fields than date. (Anyway maybe this is not an
important enough issue to create more work for translators.)

+ if (tm_hour < 0 || tm_hour > HOURS_PER_DAY)
+ ereport(ERROR,
+ (errcode(ERRCODE_DATETIME_FIELD_OVERFLOW),
+ errmsg("hours field in time value out of range: \"%02d\"",
+ tm_hour)));
+
+ if (tm_min < 0 || tm_min > MINS_PER_HOUR - 1)
+ ereport(ERROR,
+ (errcode(ERRCODE_DATETIME_FIELD_OVERFLOW),
+ errmsg("minutes field in time value out of range: \"%02d\"",
+ tm_min)));
+
+ if (sec < 0.0 || sec > (float8) SECS_PER_MINUTE)
+ ereport(ERROR,
+ (errcode(ERRCODE_DATETIME_FIELD_OVERFLOW),
+ errmsg("seconds field in time value out of range: \"%0*.*f\"",
+ MAX_TIME_PRECISION + 3,
+ MAX_TIME_PRECISION, fabs(sec))));
+
+ /* test for > 24:00:00 */
+ if ((tm_hour == HOURS_PER_DAY && (tm_min > 0 || sec > 0.0)))
+ ereport(ERROR,
+ (errcode(ERRCODE_DATETIME_FIELD_OVERFLOW),
+ errmsg("time value out of range: \"%02d:%02d:%0*.*f\"",
+ tm_hour, tm_min,
+ MAX_TIME_PRECISION + 3,
+ MAX_TIME_PRECISION, fabs(sec))));

Other than that (and fixing regression tests as appropriate), I think
the attached, which has mild corrections over your v5, is ready to
commit. (You had one missing semicolon in the float timestamp case.)

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachment Content-Type Size
make_date_v6.patch text/x-diff 8.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kevin Grittner 2013-10-11 21:43:57 Re: drop-index-concurrently-1 on master fails at serializable
Previous Message Andres Freund 2013-10-11 21:30:26 Re: [RFC] Extend namespace of valid guc names