From 26fb850af01b4ba5c1d767c9b7cb2c688f1e552d Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Wed, 9 May 2012 17:24:19 +0200 Subject: [PATCH] RRTimeslice: added a cast to timestamp. --- src/postrr.h.in | 2 ++ src/postrr.sql.in | 9 +++++++++ src/rrtimeslice.c | 18 ++++++++++++++++++ src/uninstall_postrr.sql | 2 ++ 4 files changed, 31 insertions(+) diff --git a/src/postrr.h.in b/src/postrr.h.in index 2d32f1c..bca014a 100644 --- a/src/postrr.h.in +++ b/src/postrr.h.in @@ -78,6 +78,8 @@ rrtimeslice_typmodout(PG_FUNCTION_ARGS); /* casts */ Datum rrtimeslice_to_rrtimeslice(PG_FUNCTION_ARGS); +Datum +rrtimeslice_to_timestamp(PG_FUNCTION_ARGS); /* comparison operators */ Datum diff --git a/src/postrr.sql.in b/src/postrr.sql.in index 8596cf8..ed51ab6 100644 --- a/src/postrr.sql.in +++ b/src/postrr.sql.in @@ -100,6 +100,15 @@ CREATE CAST (rrtimeslice AS rrtimeslice) WITH FUNCTION RRTimeslice(rrtimeslice, integer, boolean) AS IMPLICIT; +CREATE OR REPLACE FUNCTION Tstamp(rrtimeslice) + RETURNS timestamp + AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'rrtimeslice_to_timestamp' + LANGUAGE 'C' IMMUTABLE STRICT; + +CREATE CAST (rrtimeslice AS timestamp) + WITH FUNCTION Tstamp(rrtimeslice); + -- EXPLICIT + CREATE OR REPLACE FUNCTION rrtimeslice_seq_eq(rrtimeslice, rrtimeslice) RETURNS boolean AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'rrtimeslice_seq_eq' diff --git a/src/rrtimeslice.c b/src/rrtimeslice.c index a91a9de..7207dea 100644 --- a/src/rrtimeslice.c +++ b/src/rrtimeslice.c @@ -207,6 +207,7 @@ PG_FUNCTION_INFO_V1(rrtimeslice_typmodin); PG_FUNCTION_INFO_V1(rrtimeslice_typmodout); PG_FUNCTION_INFO_V1(rrtimeslice_to_rrtimeslice); +PG_FUNCTION_INFO_V1(rrtimeslice_to_timestamp); PG_FUNCTION_INFO_V1(rrtimeslice_seq_eq); PG_FUNCTION_INFO_V1(rrtimeslice_seq_ne); @@ -472,6 +473,23 @@ rrtimeslice_to_rrtimeslice(PG_FUNCTION_ARGS) PG_RETURN_RRTIMESLICE_P(tslice); } /* rrtimeslice_to_rrtimeslice */ +Datum +rrtimeslice_to_timestamp(PG_FUNCTION_ARGS) +{ + rrtimeslice_t *tslice; + + if (PG_NARGS() != 1) + ereport(ERROR, ( + errmsg("rrtimeslice_to_timestamp() " + "expects one argument"), + errhint("Usage: rrtimeslice_to_timestamp" + "(rrtimeslice)") + )); + + tslice = PG_GETARG_RRTIMESLICE_P(0); + PG_RETURN_TIMESTAMP(tslice->tstamp); +} /* rrtimeslice_to_timestamp */ + int rrtimeslice_seq_cmp_internal(rrtimeslice_t *ts1, rrtimeslice_t *ts2) { diff --git a/src/uninstall_postrr.sql b/src/uninstall_postrr.sql index ce5e945..e670f27 100644 --- a/src/uninstall_postrr.sql +++ b/src/uninstall_postrr.sql @@ -33,6 +33,8 @@ DROP FUNCTION IF EXISTS RRTimeslice_validate(integer); DROP CAST IF EXISTS (rrtimeslice AS rrtimeslice); DROP FUNCTION IF EXISTS RRTimeslice(rrtimeslice, integer, boolean); +DROP CAST IF EXISTS (rrtimeslice AS timestamp); +DROP FUNCTION IF EXISTS Tstamp(rrtimeslice); DROP TYPE RRTimeslice CASCADE; DROP FUNCTION IF EXISTS RRTimeslice_typmodin(cstring[]); DROP FUNCTION IF EXISTS RRTimeslice_typmodout(integer); -- 2.30.2