pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedto_timestamp function calculation error
2+ messages / 2 participants
[nested] [flat]
* to_timestamp function calculation error
@ 2024-12-17 11:51 myzhen <zhenmingyang@yeah.net>
2024-12-17 15:31 ` Re: to_timestamp function calculation error Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: myzhen @ 2024-12-17 11:51 UTC (permalink / raw)
To: pgsql-bugs
When calling the to_timestamp function, if the actual parameter passed is a negative year and you specify BC, this will cause to_timestamp to return an AD date.
example:select to_timestamp('-2011-2-18 15:13:14 BC', 'YYYY-MM-DD HH24:MI:SS BC');
I tested is as follows:
postgres=# select to_timestamp('-2011-2-18 15:13:14', 'YYYY-MM-DD HH24:MI:SS BC');
to_timestamp
---------------------------------
2011-02-18 15:13:14+08:05:43 BC
(1 row)
postgres=# select to_timestamp('-2011-2-18 15:13:14 BC', 'YYYY-MM-DD HH24:MI:SS BC');
to_timestamp
------------------------
2011-02-18 15:13:14+08
(1 row)
postgres=# select to_timestamp('-2011-2-18 15:13:14 BC', 'YYYY-MM-DD HH24:MI:SS BC') = to_timestamp('2011-2-18 15:13:14', 'YYYY-MM-DD HH24:MI:SS');
?column?
----------
t
(1 row)
postgres=#
I found the following code snippet in do_to_timestamp function:
{
/* If a 4-digit year is provided, we use that and ignore CC. */
tm->tm_year = tmfc.year;
if (tmfc.bc)
tm->tm_year = -tm->tm_year;
/* correct for our representation of BC years */
if (tm->tm_year < 0)
tm->tm_year++;
}
As long as tmfc.bc is true, tm->tm_year = tm->tm_year * -1, that's what led to this scene.
I haven't tested on other DBMS so I'm not sure if that's an issue.
Best regards
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: to_timestamp function calculation error
2024-12-17 11:51 to_timestamp function calculation error myzhen <zhenmingyang@yeah.net>
@ 2024-12-17 15:31 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2024-12-17 15:31 UTC (permalink / raw)
To: myzhen <zhenmingyang@yeah.net>; +Cc: pgsql-bugs
myzhen <zhenmingyang@yeah.net> writes:
> When calling the to_timestamp function, if the actual parameter passed is a negative year and you specify BC, this will cause to_timestamp to return an AD date.
I believe this is intentional.
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2024-12-17 15:31 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-12-17 11:51 to_timestamp function calculation error myzhen <zhenmingyang@yeah.net>
2024-12-17 15:31 ` Tom Lane <tgl@sss.pgh.pa.us>
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