(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