Re: Suggestions for 7.3 date handling - Mailing list pgsql-hackers

From Thomas Lockhart
Subject Re: Suggestions for 7.3 date handling
Date
Msg-id 3C62B982.E77A74B6@fourpalms.org
Whole thread Raw
In response to Re: Suggestions for 7.3 date handling  ("Christopher Kings-Lynne" <chriskl@familyhealth.com.au>)
Responses Re: Suggestions for 7.3 date handling  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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


pgsql-hackers by date:

Previous
From: Thomas Lockhart
Date:
Subject: Re: Threaded PosgreSQL server
Next
From: Steven Singer
Date:
Subject: Re: Replication