Re: Suggestions for 7.3 date handling

From: Thomas Lockhart <lockhart(at)fourpalms(dot)org>
To: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
Cc: Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Suggestions for 7.3 date handling
Date: 2002-02-07 17:29:38
Message-ID: 3C62B982.E77A74B6@fourpalms.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

(resent, with changes)

> OK, we have some legacy columns that use int4 as their type. It would be
> nice to be able to do easy date handling with them.

How about this? Folding in Peter's suggestion to use a multiplication
operator rather than a text string conversion which I originally
proposed:

thomas=# create or replace function date_part(text,int4)
thomas-# returns float8 as
thomas-# 'select date_part($1, timestamp without time zone \'epoch\'
thomas-# + (interval '1 sec' * $2));' language 'sql';

thomas=# select extract('epoch' from timestamp without time zone
'today'),
thomas-# extract('epoch' from 1013040000);
date_part | date_part
------------+------------
1013040000 | 1013040000

Seems to provide what you want, and you don't have to do any coding.

btw, I like that "create or replace" we have now!

- Thomas

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2002-02-07 17:41:56 Re: Implementation details of schema permissions?
Previous Message Thomas Lockhart 2002-02-07 17:22:56 Re: Threaded PosgreSQL server