Thread: Oracle-Style Date Functions

Oracle-Style Date Functions

From
David Rickard
Date:
Has anyone developed PostgreSQL versions of the Oracle date functions?  I'm especially interested in ports of ADD_MONTHS and NEXT_DAY, or hints on replicating them in PostgreSQL.
Thanks.

--

David Rickard
Software Engineer
The GTS Companies
A TechBooks Company

----------------------------------------------------------------------------------
The GTS Companies:
GTS Publishing Services, GTS Graphics, GTS Innova:
Your Single-Source Solution!
Los Angeles CA  *  York, PA  *  Boston MA  *  New Delhi, India
----------------------------------------------------------------------------------


David.Rickard@GTSCompanies.com
Visit us on the World Wide Web
http://www.gtscompanies.com
5650 Jillson St., Los Angeles, CA 90040
(323) 888-8889 x331
(323) 888-1849 [fax]

Re: Oracle-Style Date Functions

From
Josh Berkus
Date:
David,

> Has anyone developed PostgreSQL versions of the Oracle date functions?  I'm
> especially interested in ports of ADD_MONTHS and NEXT_DAY, or hints on
> replicating them in PostgreSQL.

Trivial:

CREATE FUNCTION add_months (timestamp, integer)
RETURNS timestamp AS '
SELECT $1 + (''1 month''::INTERVAL * $2);
' LANGUAGE SQL IMMUTABLE, STRICT;

CREATE FUNCTION NEXT_DAY (timestamp)
RETURNS timestamp AS '
SELCET $1 + ''1 day''::INTERVAL;
' LANGUAGE SQL IMMUTABLE, STRICT;

--
Josh Berkus
Aglio Database Solutions
San Francisco