Code

RRTimeslice: added a cast to timestamp.
authorSebastian Harl <sh@tokkee.org>
Wed, 9 May 2012 15:24:19 +0000 (17:24 +0200)
committerSebastian Harl <sh@tokkee.org>
Wed, 9 May 2012 15:24:19 +0000 (17:24 +0200)
src/postrr.h.in
src/postrr.sql.in
src/rrtimeslice.c
src/uninstall_postrr.sql

index 2d32f1cf5511a234d3eab03050b5e5a8fff7991f..bca014a9d47591294dd7dfb4702ee9dfb7c2d3ab 100644 (file)
@@ -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
index 8596cf8e66d3162726ba670535e77e5dfaa9d0a7..ed51ab676f2de477039986a248bcbde81c482bf8 100644 (file)
@@ -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'
index a91a9de95981a1fa840e29d6630a435b74961dba..7207dea04bdab2a0414360197209bd7d4a253165 100644 (file)
@@ -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)
 {
index ce5e945daccdc9bd1227cd2a80941540ba3af079..e670f27cdcd9f1cf47b4ccd4ddf0f60547ac12ef 100644 (file)
@@ -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);