Re: bug in date_part() function in 6.5.2, 7.0.2

From: Karel Zak <zakkr(at)zf(dot)jcu(dot)cz>
To: Thomas Lockhart <lockhart(at)alumni(dot)caltech(dot)edu>, analyst(at)sibinet(dot)ru, pgsql-bugs(at)postgresql(dot)org
Subject: Re: bug in date_part() function in 6.5.2, 7.0.2
Date: 2000-09-06 07:21:09
Message-ID: Pine.LNX.3.96.1000906091009.15689D-100000@ara.zf.jcu.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

> Sample Code
> create table oops (date date);
>
> insert into oops (date) values (to_date('24.03.2000','dd.mm.yyyy'));
> insert into oops (date) values (to_date('25.03.2000','dd.mm.yyyy'));
> insert into oops (date) values (to_date('26.03.2000','dd.mm.yyyy'));
> insert into oops (date) values (to_date('27.03.2000','dd.mm.yyyy'));
>
> select
> date::date
> ,date_part('day',date::date)
> ,date_part('dow',date::date)
> from oops
> order by date;
>
> ?column? | date_part | date_part
> ------------+-----------+-----------
> 24.03.2000 | 24 | 5
> 25.03.2000 | 25 | 6
> 26.03.2000 | 25 | 6
> 27.03.2000 | 27 | 1
> (4 rows)

Interesting...

test=# select date::timestamp, date_part('day', date), to_char(date, 'DD')
from oops;
?column? | date_part | to_char
------------------------+-----------+---------
2000-03-24 00:00:00+01 | 24 | 24
2000-03-25 00:00:00+01 | 25 | 25
2000-03-25 23:00:00+01 | 25 | 25
2000-03-27 00:00:00+02 | 27 | 27
(4 rows)

to_char() and date_part() has different code but some result, a problem
can't be in date_part()...

test=# select date::timestamp from oops;
?column?
------------------------
2000-03-24 00:00:00+01
2000-03-25 00:00:00+01
2000-03-25 23:00:00+01
^^^^
????
2000-03-27 00:00:00+02
(4 rows)

....it's not date_part() bug, it's to_date() bug:

test=# select to_date('26.03.2000','dd.mm.yyyy')::timestamp;
?column?
------------------------
2000-03-25 23:00:00+01
^^^
! Bug !

test=# select to_timestamp('26.03.2000','dd.mm.yyyy');
to_timestamp
------------------------
2000-03-26 00:00:00+01
^^^
! correct !

But to_date() call to_timestamp() only:

Datum
to_date(PG_FUNCTION_ARGS)
{
/* Quick hack: since our inputs are just like to_timestamp,
* hand over the whole input info struct...
*/
return DirectFunctionCall1(timestamp_date, to_timestamp(fcinfo));
}

Comments, some idea?

Karel

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Piers Scannell 2000-09-06 09:19:07 RE: Possible bug in referential integrity system
Previous Message pgsql-bugs 2000-09-06 06:57:34 bug in date_part() function in 6.5.2, 7.0.2