Re: Max function on Timestamp

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: "Esteban Chiner Sanz" <echiner(at)tissat(dot)es>, pgsql-sql(at)postgreSQL(dot)org
Subject: Re: Max function on Timestamp
Date: 1999-09-06 11:37:50
Message-ID: l03130300b3f9532becaf@[147.233.159.109]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Herouth Maoz 1999-09-06 12:29:27 Re: [GENERAL] GEQO and KSQO problem.
Previous Message Marzullo Laurent 1999-09-06 10:44:26 Error number

Browse pgsql-sql by date

  From Date Subject
Next Message pwc 1999-09-06 12:11:04
Previous Message Dipankar Chakrabarti 1999-09-06 06:43:11 Re: pgsql-sql-digest V1 #344