On Feb 12, 2008, at 3:50 PM, till wrote:
On Feb 12, 2008 10:28 PM, Dalibor Andzakovic Dalibor.Andzakovic@swerve.co.nz wrote:
One fix for PostgreSQL would be to declare a function.
Something like:
CREATE FUNCTION unix_timestamp (timestamptz) RETURNS numeric AS $BODY$ BEGIN RETURN EXTRACT(EPOCH FROM $1); END; $BODY$ LANGUAGE plpgsql;
Would do the job.
Dali,
just out of curiousity - for how long does this "persist" in
PostgreSQL?
You could put it in the schema for the database, and it would always
be there.
Put this in the PostgreSQL SQL file ( postgres.initial.sql and
postgres.update.sql )
CREATE FUNCTION unix_timestamp () RETURNS double precision AS ' SELECT extract(epoch from date_trunc(''seconds'', current_timestamp)); ' LANGUAGE SQL;
Check your work by listing the defined functions that start with "unix"
[chasd@server3 trunk]$ psql roundcube Welcome to psql 7.4.11, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms \h for help with SQL commands ? for help on internal slash commands \g or terminate with semicolon to execute query \q to quit
roundcube=# roundcube=# \df unix* List of functions Result data type | Schema | Name | Argument data types ------------------+--------+----------------+--------------------- double precision | public | unix_timestamp |
Use it
roundcube=# select unix_timestamp() as tz_db; tz_db
1202857954
Charles Dostale System Admin - Silver Oaks Communications http://www.silveroaks.com/ 824 17th Street, Moline IL 61265
List info: http://lists.roundcube.net/dev/