DATE_PART() BUG? - Mailing list pgsql-bugs

From Peter Kelly
Subject DATE_PART() BUG?
Date
Msg-id 81568ACE3F6BD41189D90050046EB17A093DFC@bart.int.ets.net
Whole thread Raw
List pgsql-bugs
Here are operational details:

RedHat Linux 7.0:

Linux version 2.2.17-14 (root@porky.devel.redhat.com) (gcc version
egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)) #1 Mon Feb 5 15:25:12 EST
2001

PostgreSQL Version info:

postgresql-7.0.2-17
postgresql-server-7.0.2-17
postgresql-devel-7.0.2-17

tbs=# SELECT version();
                           version
-------------------------------------------------------------
 PostgreSQL 7.0.2 on i686-pc-linux-gnu, compiled by gcc 2.96
(1 row)

Server/Memory Info:

Server is a Compaq Proliant 2500, Pentium Pro 200 with 256 MB RAM.

[root@lisa cgi-bin]# cat /proc/meminfo
        total:    used:    free:  shared: buffers:  cached:
Mem:  263831552 151920640 111910912 82890752 47788032 74584064
Swap: 271556608  7589888 263966720
MemTotal:    257648 kB
MemFree:     109288 kB
MemShared:    80948 kB
Buffers:      46668 kB
Cached:       72836 kB
BigTotal:         0 kB
BigFree:          0 kB
SwapTotal:   265192 kB
SwapFree:    257780 kB

BUG:
----

We have an SQL statement that is giving wrong output.

Here is an example of the whole statement:

SELECT
    *, Date_Part('Month', CAST ('5/25/2001' AS DATE))
    - Date_Part('Month', purchasedate ) + 1 AS thismonth
FROM customers
WHERE CAST('5/25/2001' AS DATE) - CAST ('12 months' AS INTERVAL) <
purchasedate
AND purchasedate <= CAST ('5/25/2001' AS DATE)
AND 25 <= Date_Part('Day', purchasedate)
AND Date_Part('Day', purchasedate) <= 25
AND merchantnumber != 'odc12'
ORDER BY thismonth, id_num

Here is a simple example:

SELECT DATE_PART('DAY', CAST('04/1/2001' AS DATE)) as dayofmonth
 dayofmonth
----------
         31

Why does April 1st display as May 31st?

Here is the table def:

CREATE TABLE "customers" (
        "id_num" int4 DEFAULT nextval('customers_id_num_seq'::text) NOT
NULL,
        "merchantnumber" character varying(9),
        "producttype" character varying(7),
        "purchasedate" date,
        "emailaddress" character varying(60),
        "firstname" character varying(25),
        "lastname" character varying(50),
        "customerfullname" character varying(40),
        "salesordernumber" character varying(20),
        "notes" character varying(80)
);

Thanks


--
Peter Kelly, ETS.NET Inc.

Email:        mailto:pkelly@ets.net
PGP Key:    http://www.ets.net/pkelly-pgp.html
Phone:        905-713-9978
Fax:         905-726-8118

Visit us at http://www.ets.net!
--

"Opinions expressed are property of my evil twin, not my employer."

pgsql-bugs by date:

Previous
From: "Panon, Paul-Andre"
Date:
Subject: SQL update statements are failing if submitted in sequence on sam e connection
Next
From: Paul-Andre Panon
Date:
Subject: SQL update statements are failing if submitted in sequence on same connection