summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8aafc82)
raw | patch | inline | side by side (parent: 8aafc82)
author | Sebastian Harl <sh@tokkee.org> | |
Mon, 30 Apr 2012 12:52:34 +0000 (14:52 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Mon, 30 Apr 2012 12:52:34 +0000 (14:52 +0200) |
Both casts are marked 'AS ASSIGNMENT'.
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 6d202e20da6f525c63c470038f5015edcdd1c001..b47e3f87d169a107f63177df503192e3c6b722fb 100644 (file)
--- a/src/cdata.c
+++ b/src/cdata.c
PG_FUNCTION_INFO_V1(cdata_typmodout);
PG_FUNCTION_INFO_V1(cdata_to_cdata);
+PG_FUNCTION_INFO_V1(int32_to_cdata);
/*
* public API
PG_RETURN_CDATA_P(data);
} /* cdata_to_cdata */
+Datum
+int32_to_cdata(PG_FUNCTION_ARGS)
+{
+ int32 i_val;
+ int32 typmod;
+
+ cdata_t *data;
+
+ if (PG_NARGS() != 3)
+ ereport(ERROR, (
+ errmsg("int32_to_cdata() expects three arguments"),
+ errhint("Usage: int32_to_cdata"
+ "(integer, typmod, is_explicit)")
+ ));
+
+ i_val = PG_GETARG_INT32(0);
+ typmod = PG_GETARG_INT32(1);
+
+ data = (cdata_t *)palloc0(sizeof(*data));
+
+ data->value = (float8)i_val;
+ data->undef_num = 0;
+ data->val_num = 1;
+
+ if (typmod >= 0)
+ data->cf = typmod;
+ else
+ data->cf = CF_AVG;
+
+ PG_RETURN_CDATA_P(data);
+} /* int32_to_cdata */
+
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
diff --git a/src/postrr.h.in b/src/postrr.h.in
index 95582db6eaf3a7d22f2f311f0fb2fb0cef1cf0d6..92025db3589fe438f457000ed41f985558e048c5 100644 (file)
--- a/src/postrr.h.in
+++ b/src/postrr.h.in
/* casts */
Datum
cdata_to_cdata(PG_FUNCTION_ARGS);
+Datum
+int32_to_cdata(PG_FUNCTION_ARGS);
#endif /* ! POSTRR_H */
diff --git a/src/postrr.sql.in b/src/postrr.sql.in
index cf24fced1003d0d4f57d92165c5a19e37ad664d9..ffdb3a718350859625acbef996c37a5db570c733 100644 (file)
--- a/src/postrr.sql.in
+++ b/src/postrr.sql.in
WITH FUNCTION CData(cdata, integer, boolean)
AS IMPLICIT;
+CREATE CAST (numeric AS cdata)
+ WITH INOUT
+ AS ASSIGNMENT;
+
+CREATE OR REPLACE FUNCTION CData(integer, integer, boolean)
+ RETURNS cdata
+ AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'int32_to_cdata'
+ LANGUAGE 'C' IMMUTABLE STRICT;
+
+CREATE CAST (integer AS cdata)
+ WITH FUNCTION CData(integer, integer, boolean)
+ AS ASSIGNMENT;
+
COMMIT;
SET client_min_messages TO DEFAULT;