diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2015-04-26 10:33:14 -0400 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2015-04-26 10:33:14 -0400 |
commit | cac76582053ef8ea07df65fed0757f352da23705 (patch) | |
tree | 6ae01041aa61db9d686638b9d4c3ccd30d7c6487 /contrib/ltree_plpython/ltree_plpython.c | |
parent | f320cbb615e0374b18836337713239da58705cf3 (diff) | |
download | postgresql-cac76582053ef8ea07df65fed0757f352da23705.tar.gz postgresql-cac76582053ef8ea07df65fed0757f352da23705.zip |
Add transforms feature
This provides a mechanism for specifying conversions between SQL data
types and procedural languages. As examples, there are transforms
for hstore and ltree for PL/Perl and PL/Python.
reviews by Pavel Stěhule and Andres Freund
Diffstat (limited to 'contrib/ltree_plpython/ltree_plpython.c')
-rw-r--r-- | contrib/ltree_plpython/ltree_plpython.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/contrib/ltree_plpython/ltree_plpython.c b/contrib/ltree_plpython/ltree_plpython.c new file mode 100644 index 00000000000..111e3e356e5 --- /dev/null +++ b/contrib/ltree_plpython/ltree_plpython.c @@ -0,0 +1,32 @@ +#include "postgres.h" +#include "fmgr.h" +#include "plpython.h" +#include "ltree.h" + +PG_MODULE_MAGIC; + + +PG_FUNCTION_INFO_V1(ltree_to_plpython); +Datum ltree_to_plpython(PG_FUNCTION_ARGS); + +Datum +ltree_to_plpython(PG_FUNCTION_ARGS) +{ + ltree *in = PG_GETARG_LTREE(0); + int i; + PyObject *list; + ltree_level *curlevel; + + list = PyList_New(in->numlevel); + + curlevel = LTREE_FIRST(in); + for (i = 0; i < in->numlevel; i++) + { + PyList_SetItem(list, i, PyString_FromStringAndSize(curlevel->name, curlevel->len)); + curlevel = LEVEL_NEXT(curlevel); + } + + PG_FREE_IF_COPY(in, 0); + + return PointerGetDatum(list); +} |