Thread: to_date/to timestamp going to BC

to_date/to timestamp going to BC

From
jason.servetar@ccgenesis.com
Date:
Can someone tell me if this is a bug with the date functions or am I using
them incorrectly?
If anyone has a workaround for this I could use some help this data
conversion.

dev=> create table test_date (dt varchar(100));
CREATE

dev=> insert into test_date values ('March 11, 1997');
INSERT 706020 1

dev=> select dt, to_date(dt, 'Month dd, yyyy'), to_timestamp(dt, 'Month dd,
yyyy') from test_date;      dt       |    to_date    | to_timestamp  
----------------+---------------+---------------March 11, 1997 | 0001-03-19 BC | 0001-03-19 BC

drw_dev=> select version();                           version                             
----------------------------------------------------------------PostgreSQL 7.1 on sparc-sun-solaris2.6, compiled by GCC
2.95.2
(1 row)





Re: to_date/to timestamp going to BC

From
Tom Lane
Date:
jason.servetar@ccgenesis.com writes:
> Can someone tell me if this is a bug with the date functions or am I using
> them incorrectly?

I get the right thing when I use the right format:

regression=# select dt, to_timestamp(dt, 'FMMonth dd, yyyy') from test_date;      dt       |      to_timestamp
----------------+------------------------March 11, 1997 | 1997-03-11 00:00:00-05
(1 row)

However, I'd agree that this shows a lack of robustness in to_timestamp;
it's not objecting to data that doesn't match the format.
        regards, tom lane


Re: to_date/to timestamp going to BC

From
jason.servetar@ccgenesis.com
Date:
Thanks Tom that worked great.
I guess I should have not skipped the
FM prefix section of the date conversion doc.

drw_dev-> to_timestamp(dt, 'FMMonth dd, yyyy') from test_date;      dt       |  to_date   |      to_timestamp      
----------------+------------+------------------------March 11, 1997 | 1997-03-11 | 1997-03-11 00:00:00-07

-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
Sent: Wednesday, October 03, 2001 3:14 PM
To: Servetar, Jason
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] to_date/to timestamp going to BC 


jason.servetar@ccgenesis.com writes:
> Can someone tell me if this is a bug with the date functions or am I using
> them incorrectly?

I get the right thing when I use the right format:

regression=# select dt, to_timestamp(dt, 'FMMonth dd, yyyy') from test_date;      dt       |      to_timestamp
----------------+------------------------March 11, 1997 | 1997-03-11 00:00:00-05
(1 row)

However, I'd agree that this shows a lack of robustness in to_timestamp;
it's not objecting to data that doesn't match the format.
        regards, tom lane


Re: to_date/to timestamp going to BC

From
Karel Zak
Date:
On Wed, Oct 03, 2001 at 05:14:02PM -0400, Tom Lane wrote:
> jason.servetar@ccgenesis.com writes:
> > Can someone tell me if this is a bug with the date functions or am I using
> > them incorrectly?
> 
> I get the right thing when I use the right format:
> 
> regression=# select dt, to_timestamp(dt, 'FMMonth dd, yyyy') from test_date;
>        dt       |      to_timestamp
> ----------------+------------------------
>  March 11, 1997 | 1997-03-11 00:00:00-05
> (1 row)
> 
> However, I'd agree that this shows a lack of robustness in to_timestamp;
> it's not objecting to data that doesn't match the format.
The manual is transparent about this. I can add feauture that will
check everythig, but users who knows read manual and use already 
debugged queries will spend CPU on non-wanted code. 

Hmm.. I look at Oracle, and it allows parse queries like:

SVRMGR> select to_date('March 11, 1997', 'Month dd, yyyy') from dual;
TO_DATE('
---------
11-MAR-97
1 row selected.

.. well, I add it to my TODO for 7.3 (I plan rewrite several things 
in to_* functions).
Karel

-- Karel Zak  <zakkr@zf.jcu.cz>http://home.zf.jcu.cz/~zakkr/C, PostgreSQL, PHP, WWW, http://docs.linux.cz,
http://mape.jcu.cz


Re: to_date/to timestamp going to BC

From
"Josh Berkus"
Date:
Karel,

> .. well, I add it to my TODO for 7.3 (I plan rewrite several things
> in to_* functions).

How about a to_char function for INTERVAL?  Please, oh please?

-Josh

______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco

Attachment

Re: to_date/to timestamp going to BC

From
Karel Zak
Date:
On Thu, Oct 04, 2001 at 07:44:14AM -0700, Josh Berkus wrote:
> Karel,
> 
> > .. well, I add it to my TODO for 7.3 (I plan rewrite several things 
> > in to_* functions).
> 
> How about a to_char function for INTERVAL?  Please, oh please?
oh, needn't please.. already in right now breeding 7.2 :-)

test=# SELECT to_char('5months 3sec 4h 1min'::interval, 'HH:MI:SS Mon');  to_char
--------------04:01:03 May
(1 row)
Karel

-- Karel Zak  <zakkr@zf.jcu.cz>http://home.zf.jcu.cz/~zakkr/C, PostgreSQL, PHP, WWW, http://docs.linux.cz,
http://mape.jcu.cz


Re: to_date/to timestamp going to BC

From
jason.servetar@ccgenesis.com
Date:
Thanks Karel,Good call, you guessed it. I was just using my Oracle knowledge of
the to_date and applying it to the results I was expecting in pgsql. Guess I
should not make those assumptions....

-----Original Message-----
From: Karel Zak [mailto:zakkr@zf.jcu.cz]
Sent: Thursday, October 04, 2001 2:42 AM
To: Tom Lane
Cc: Servetar, Jason; pgsql-sql@postgresql.org
Subject: Re: [SQL] to_date/to timestamp going to BC


On Wed, Oct 03, 2001 at 05:14:02PM -0400, Tom Lane wrote:
> jason.servetar@ccgenesis.com writes:
> > Can someone tell me if this is a bug with the date functions or am I
using
> > them incorrectly?
> 
> I get the right thing when I use the right format:
> 
> regression=# select dt, to_timestamp(dt, 'FMMonth dd, yyyy') from
test_date;
>        dt       |      to_timestamp
> ----------------+------------------------
>  March 11, 1997 | 1997-03-11 00:00:00-05
> (1 row)
> 
> However, I'd agree that this shows a lack of robustness in to_timestamp;
> it's not objecting to data that doesn't match the format.
The manual is transparent about this. I can add feauture that will
check everythig, but users who knows read manual and use already 
debugged queries will spend CPU on non-wanted code. 

Hmm.. I look at Oracle, and it allows parse queries like:

SVRMGR> select to_date('March 11, 1997', 'Month dd, yyyy') from dual;
TO_DATE('
---------
11-MAR-97
1 row selected.

.. well, I add it to my TODO for 7.3 (I plan rewrite several things 
in to_* functions).
Karel

-- Karel Zak  <zakkr@zf.jcu.cz>http://home.zf.jcu.cz/~zakkr/C, PostgreSQL, PHP, WWW, http://docs.linux.cz,
http://mape.jcu.cz