Re: BUG #19935: comparing timestamps milliseocnds = microseconds

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: stepya(at)ukr(dot)net
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19935: comparing timestamps milliseocnds = microseconds
Date: 2026-11-25 18:46:31
Message-ID: 1304396.1795632391@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> The issue is reproducible in up to 19 and looks like it is expected
> behavior. but it is too strage behavior.

It's acting as designed.

> to_timestamp('20261124-09:57:25.000123', 'YYYYMMDD-hh:mi:ss.ms') evaluates
> to 123 milliseconds, whereas the expected result is 0 milliseconds.

You told it the field was milliseconds, so it read it as milliseconds.
If you wanted it to be read as microseconds, you should have said "us".

In general, I don't have much sympathy for arguments about how
to_timestamp should interpret input loosely. If you want the
"natural" reading of the input string, just casting text to timestamp
will almost always do what you want. The point of to_timestamp is
to be able to parse strings that are in some weird format. But you
have to describe that format accurately.

Even if I agreed this was wrong, I'd be hesitant to change the
behavior for fear of breaking existing use-cases.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Previous Message Tom Lane 2026-11-25 18:29:50 Re: BUG #19948: Unqualified prefix <= operator is rejected despite being first in search_path