to_timestamp not stable if date string shorter than template

Lists: pgsql-bugs
From: "Stacy White" <harsh(at)computer(dot)org>
To: <pgsql-bugs(at)postgresql(dot)org>
Cc: "Aaron Harsh" <ajh(at)rentrak(dot)com>
Subject: to_timestamp not stable if date string shorter than template
Date: 2003-09-01 20:34:11
Message-ID: 000701c370c8$67738560$0200a8c0@grownups
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Architecture: Intel Pentium
Operating System: Redhat 7.2 (Linux 2.4.17)
PostgreSQL version: PostgreSQL-7.3.4
Compiler used: gcc 3.01

to_timestamp appears to pick up the time-of-day from the previous call's
return value if a date string has no time component. For example:

# select to_timestamp('2003-06-01', 'YYYY-MM-DD HH24:MI:SS') ;
to_timestamp
------------------------
2003-06-01 00:00:00-07
(1 row)

# select to_timestamp('2003-06-02 12:13:14', 'YYYY-MM-DD HH24:MI:SS') ;
to_timestamp
------------------------
2003-06-02 12:13:14-07
(1 row)

# select to_timestamp('2003-06-01', 'YYYY-MM-DD HH24:MI:SS') ;
to_timestamp
------------------------
2003-06-01 12:13:14-07
(1 row)

I suppose the proper behavior in this situation is debatable, but it seems
that the function should be stable.

FWIW, Oracle's behavior in this case (with 'to_date') is to return
'2003-06-01 00:00:00'.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Stacy White" <harsh(at)computer(dot)org>
Cc: pgsql-bugs(at)postgresql(dot)org, "Aaron Harsh" <ajh(at)rentrak(dot)com>
Subject: Re: to_timestamp not stable if date string shorter than template
Date: 2003-09-02 23:05:00
Message-ID: 21044.1062543900@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

"Stacy White" <harsh(at)computer(dot)org> writes:
> to_timestamp appears to pick up the time-of-day from the previous call's
> return value if a date string has no time component. For example:

Weird. I do not see that here, on either 7.3.4 or current sources.
Can anyone else reproduce it?

For the record, I get:

regression=# select to_timestamp('2003-06-01', 'YYYY-MM-DD HH24:MI:SS') ;
to_timestamp
------------------------
2003-06-01 00:00:00-04
(1 row)

regression=# select to_timestamp('2003-06-02 12:13:14', 'YYYY-MM-DD HH24:MI:SS') ;
to_timestamp
------------------------
2003-06-02 12:13:14-04
(1 row)

regression=# select to_timestamp('2003-06-01', 'YYYY-MM-DD HH24:MI:SS') ;
to_timestamp
------------------------
2003-06-01 00:00:00-04
(1 row)

regards, tom lane


From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Stacy White <harsh(at)computer(dot)org>, <pgsql-bugs(at)postgresql(dot)org>, Aaron Harsh <ajh(at)rentrak(dot)com>
Subject: Re: to_timestamp not stable if date string shorter than
Date: 2003-09-02 23:39:26
Message-ID: 20030902163331.M53013-100000@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


On Tue, 2 Sep 2003, Tom Lane wrote:

> "Stacy White" <harsh(at)computer(dot)org> writes:
> > to_timestamp appears to pick up the time-of-day from the previous call's
> > return value if a date string has no time component. For example:
>
> Weird. I do not see that here, on either 7.3.4 or current sources.
> Can anyone else reproduce it?
>
> For the record, I get:
>
> regression=# select to_timestamp('2003-06-01', 'YYYY-MM-DD HH24:MI:SS') ;
> to_timestamp
> ------------------------
> 2003-06-01 00:00:00-04
> (1 row)
>
> regression=# select to_timestamp('2003-06-02 12:13:14', 'YYYY-MM-DD HH24:MI:SS') ;
> to_timestamp
> ------------------------
> 2003-06-02 12:13:14-04
> (1 row)
>
> regression=# select to_timestamp('2003-06-01', 'YYYY-MM-DD HH24:MI:SS') ;
> to_timestamp
> ------------------------
> 2003-06-01 00:00:00-04
> (1 row)

I seem to get the incorrect behavior on my 7.4 beta 1 system. The
behavior on my machine is really wierd in fact even without times
involved:

test=# select to_timestamp('2003-06-04', 'YYYY-MM-DD HH24:MI:SS') ;
to_timestamp
------------------------
2003-06-04 00:00:00-07
(1 row)

test=# select to_timestamp('2003-06', 'YYYY-MM-DD HH24:MI:SS') ;
to_timestamp
------------------------
2003-06-04 00:00:00-07
(1 row)

test=# select to_timestamp('2003', 'YYYY-MM-DD HH24:MI:SS') ;
to_timestamp
------------------------
2003-01-01 00:04:00-08
(1 row)

test=# select to_timestamp('2003-06', 'YYYY-MM-DD HH24:MI:SS') ;
to_timestamp
------------------------
2003-06-04 00:00:00-07
(1 row)

test=# select to_timestamp('2003-07', 'YYYY-MM-DD HH24:MI:SS') ;
to_timestamp
------------------------
2003-07-04 00:00:00-07
(1 row)


From: "Mendola Gaetano" <mendola(at)bigfoot(dot)com>
To: <pgsql-bugs(at)postgresql(dot)org>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: to_timestamp not stable if date string shorter than template
Date: 2003-09-05 19:32:01
Message-ID: 008801c373e6$45da69c0$92700b3e@mm.eutelsat.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


----- Original Message -----
From: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Newsgroups: comp.databases.postgresql.bugs
Sent: Wednesday, September 03, 2003 1:05 AM
Subject: Re: to_timestamp not stable if date string shorter than template

> "Stacy White" <harsh(at)computer(dot)org> writes:
> > to_timestamp appears to pick up the time-of-day from the previous call's
> > return value if a date string has no time component. For example:
>
> Weird. I do not see that here, on either 7.3.4 or current sources.
> Can anyone else reproduce it?

I get on Postgres 7.3.3:

test=# select to_timestamp('2003-06-01', 'YYYY-MM-DD HH24:MI:SS') ;
to_timestamp
------------------------
2003-06-01 00:08:00+02
(1 row)

test=# select to_timestamp('2003-06-02 12:13:14', 'YYYY-MM-DD HH24:MI:SS') ;
to_timestamp
------------------------
2003-06-02 12:13:14+02
(1 row)

test=# select to_timestamp('2003-06-01', 'YYYY-MM-DD HH24:MI:SS') ;
to_timestamp
------------------------
2003-06-01 00:08:00+02
(1 row)

Why 00:08:00+02 ?

Regards
Gaetano Mendola