summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ea3be3a)
raw | patch | inline | side by side (parent: ea3be3a)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 10 May 2012 13:10:58 +0000 (15:10 +0200) | ||
committer | Sebastian 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 | patch | blob | history | |
src/postrr.h.in | patch | blob | history | |
src/postrr.sql.in | patch | blob | history |
diff --git a/src/cdata.c b/src/cdata.c
index 32e8e4d0b8dbad51c5ec428d95b70543faefeca6..03fefbc6c510f45556c76237472c1139895e7365 100644 (file)
--- a/src/cdata.c
+++ b/src/cdata.c
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);
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)
{
diff --git a/src/postrr.h.in b/src/postrr.h.in
index c309ef04ebb68146194c1d59f83a2b5961b6494f..798fd3fea523a84ae66e2d1111b9ce88dee8514c 100644 (file)
--- a/src/postrr.h.in
+++ b/src/postrr.h.in
cdata_to_cdata(PG_FUNCTION_ARGS);
Datum
int32_to_cdata(PG_FUNCTION_ARGS);
+Datum
+cdata_to_float8(PG_FUNCTION_ARGS);
/* aux. functions */
Datum
diff --git a/src/postrr.sql.in b/src/postrr.sql.in
index 9339e32f04ed948fc374e182d40311c999628054..68c47dfbba04114f964fdfeb007b5cb3f1851c54 100644 (file)
--- a/src/postrr.sql.in
+++ b/src/postrr.sql.in
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'