On 3/11/16, Tom Lane <t...@sss.pgh.pa.us> wrote:
> [ catches up with thread... ]
> Yes. It would be more reasonable IMO for to_date to throw an error
> because this is bad input. On the other hand, to_date mostly doesn't
> throw an error no matter how bad the input is. I think that may have
> been intentional, although its habit of producing garbage output
> instead (and not, say, NULL) is certainly not very happy-making.
> It's a bit schizophrenic for this patch to be both adding ereport's
> for year zero (thereby breaking the no-failure-on-bad-input policy)
> *and* trying to produce sane output for arguably-insane input.
> I don't really see an argument why '0001-00-00' should be accepted
> but '0000-01-01' should throw an error, but that would be the result
> if we take this patch.
Well. In case of zero year it could return the first year instead of
an exception by the same way as "MM" and "DD" do it...
> And I quite agree with Robert that it's insane
> to consider '-2-06-01' as satisfying the format 'YYYY-MM-DD'. The
> fact that it even appears to do something related to a BC year is
> an implementation artifact, and not a very nice one.
> I would be in favor of a ground-up rewrite of to_date and friends, with
> some better-stated principles (in particular, a rationale why they even
> exist when date_in and friends usually do it better)
I think they exist because date_in can't convert something like
"IYYY-IDDD" (I wonder if date_in can do so) or to parse dates/stamps
independent from the "DateStyle" parameter.
> and crisper error
> detection. But I'm not seeing the argument that hacking at the margins
> like this moves us forward on either point; what it does do is create
> another backward-compatibility hazard for any such rewrite.
> In short, I vote with Robert to reject this patch.
Accepted. Let's agree it is a case "garbage in, garbage out" and "an
> BTW, the context for the original report wasn't clear,
The context was to make "extract" and "to_date"/"to_timestamp" be
consistently reversible for "year"/"YYYY" for negative values (since
both of them support ones).
> but I wonder how
> much of the actual problem could be addressed by teaching make_date()
> and friends to accept negative year values as meaning BC.
> regards, tom lane
Thank Thomas, Robert and Tom very much for an interesting (but short)
Sent via pgsql-hackers mailing list (email@example.com)
To make changes to your subscription: