Received: from shaked.cc.openu.ac.il (shaked.cc.openu.ac.il [147.233.145.65]) by hub.org (8.9.3/8.9.3) with ESMTP id HAA25551 for ; Mon, 6 Sep 1999 07:35:59 -0400 (EDT) (envelope-from herouth@oumail.openu.ac.il) Received: from [147.233.159.109] (herouth@mac-herouth.pc.openu.ac.il [147.233.159.109]) by shaked.cc.openu.ac.il (8.8.8/8.8.8) with ESMTP id NAA08861; Mon, 6 Sep 1999 13:35:46 +0200 (IST) X-Sender: herouth@shaked.cc.openu.ac.il Message-Id: In-Reply-To: <37CE3592.2558E205@tissat.es> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Mon, 6 Sep 1999 14:37:50 +0300 To: "Esteban Chiner Sanz" , pgsql-sql@postgreSQL.org From: Herouth Maoz Subject: Re: Max function on Timestamp At 11:30 +0300 on 02/09/1999, Esteban Chiner Sanz wrote: > I have a table in my database with a timestamp field and I can't use a > max function on it. You can do it with any other date types (date, > timespan, etc.) but not with timestamp. > Is there any problem on doing it? Why isn't it implemented in PostgreSQL > 6.5.1? What would be the easiest way of doing it? You can convert to datetime and back. I have 6.4, in which conversion from datetime to timestamp is broken. I don't know whether or not it is broken in 6.5.1 as well, but if it is, you can easily define: CREATE FUNCTION dt_to_ts( datetime ) returns timestamp AS 'SELECT timestamp_in( datetime_out( $1 ) ) WHERE $1 IS NOT NULL' LANGUAGE 'sql'; Now, get your max with: SELECT dt_to_ts( max( timestamp_field::datetime ) ) FROM the_table; Herouth -- Herouth Maoz, Internet developer. Open University of Israel - Telem project http://telem.openu.ac.il/~herutma