Re: [SQL] parts of date_part()

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: Leslie Mikesell <les(at)Mcs(dot)Net>
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] parts of date_part()
Date: 1998-08-27 08:13:10
Message-ID: l03110700b20ac18f7e5d@[147.233.159.109]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

At 19:53 +0300 on 26/8/98, Leslie Mikesell wrote:

> Since I just ran across:
> psql=> select date_part('month','01-01-1998'::date);
> date_part
> ---------
> 12
> (1 row)
> and the extract() does the same in this case, I'm being a little cautious...

As a rule, I never use the type DATE, only DATETIME. I've seen too many
problems with timezones with the shorter types, and the functions
supporting them are too few for me to be comfortable with them.

My guess as to the reason of the above - and the Gurus may correct me if
I'm wrong - is that the DATE type does not contain time information. But
then, it is converted internally to DATETIME or milliseconds-since-epoch
for the sake of the function. This conversion involves your timezone, and
since you timezone is probably negative, a few hours before 1998-01-01 is
definitely December.

In my Postgres (Israeli Daylight Time):

testing=> select date_part( 'month', '01-01-1998'::date );
date_part
---------
1
(1 row)

Then again, it could be a platform problem. Have all the regression tests
passed correctly when you compiled?

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message ADM. Diego Cueva 1998-08-27 14:13:50 Counter
Previous Message Pushkar Piggott 1998-08-27 01:00:15 Another bug in GROUP BY for INSERT