Code

CData: added a cast to double precision.
authorSebastian Harl <sh@tokkee.org>
Thu, 10 May 2012 13:10:58 +0000 (15:10 +0200)
committerSebastian Harl <sh@tokkee.org>
Thu, 10 May 2012 14:22:10 +0000 (16:22 +0200)
The cast may only be done explicitly.

src/cdata.c
src/postrr.h.in
src/postrr.sql.in

index 32e8e4d0b8dbad51c5ec428d95b70543faefeca6..03fefbc6c510f45556c76237472c1139895e7365 100644 (file)
@@ -79,6 +79,7 @@ PG_FUNCTION_INFO_V1(cdata_typmodout);
 
 PG_FUNCTION_INFO_V1(cdata_to_cdata);
 PG_FUNCTION_INFO_V1(int32_to_cdata);
+PG_FUNCTION_INFO_V1(cdata_to_float8);
 
 PG_FUNCTION_INFO_V1(cdata_update);
 
@@ -331,6 +332,21 @@ int32_to_cdata(PG_FUNCTION_ARGS)
        PG_RETURN_CDATA_P(data);
 } /* int32_to_cdata */
 
+Datum
+cdata_to_float8(PG_FUNCTION_ARGS)
+{
+       cdata_t *data;
+
+       if (PG_NARGS() != 1)
+               ereport(ERROR, (
+                                       errmsg("cdata_to_float8() expects one argument"),
+                                       errhint("Usage: cdata_to_float8(cdata)")
+                               ));
+
+       data = PG_GETARG_CDATA_P(0);
+       PG_RETURN_FLOAT8(data->value);
+} /* cdata_to_float8 */
+
 Datum
 cdata_update(PG_FUNCTION_ARGS)
 {
index c309ef04ebb68146194c1d59f83a2b5961b6494f..798fd3fea523a84ae66e2d1111b9ce88dee8514c 100644 (file)
@@ -134,6 +134,8 @@ Datum
 cdata_to_cdata(PG_FUNCTION_ARGS);
 Datum
 int32_to_cdata(PG_FUNCTION_ARGS);
+Datum
+cdata_to_float8(PG_FUNCTION_ARGS);
 
 /* aux. functions */
 Datum
index 9339e32f04ed948fc374e182d40311c999628054..68c47dfbba04114f964fdfeb007b5cb3f1851c54 100644 (file)
@@ -280,6 +280,15 @@ CREATE CAST (integer AS cdata)
        WITH FUNCTION CData(integer, integer, boolean)
        AS ASSIGNMENT;
 
+CREATE OR REPLACE FUNCTION Float8(cdata)
+       RETURNS double precision
+       AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'cdata_to_float8'
+       LANGUAGE 'C' IMMUTABLE STRICT;
+
+CREATE CAST (cdata AS double precision)
+       WITH FUNCTION Float8(cdata);
+       -- EXPLICIT
+
 CREATE OR REPLACE FUNCTION CData_update(cdata, cdata)
        RETURNS cdata
        AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'cdata_update'