如何启用 hstore_plpython3u
How to enable hstore_plpython3u
扩展 hstore_plpython3u 应该按照文档中的描述转换 hstore to/from python dict,但似乎不起作用。 hstore 变成了一个字符串(似乎没有发生转换)。为什么,以及如何解决它?
The extensions for PL/Python are called hstore_plpythonu,
hstore_plpython2u, and hstore_plpython3u (see Section 45.1 for the
PL/Python naming convention). If you use them, hstore values are
mapped to Python dictionaries.
https://www.postgresql.org/docs/current/hstore.html
创建扩展
create extension plpython3u;
create extension hstore_plpython3u;
创建函数
create function type(names hstore)
returns text
language plpython3u as $$
return type(names);
$$;
调用函数
select type(hstore('name','martin'));
returns
type
---------------
<class 'str'>
(1 row)
我想明白了。来自 /contrib/hstore_plpython
中的 expected/hstore_plpython.out
文件:
CREATE FUNCTION test1arr(val hstore[]) RETURNS int
LANGUAGE plpythonu
TRANSFORM FOR TYPE hstore
AS $$
assert(val == [{'aa': 'bb', 'cc': None}, {'dd': 'ee'}])
return len(val)
$$;
SELECT test1arr(array['aa=>bb, cc=>NULL'::hstore, 'dd=>ee']);
test1arr
----------
2
扩展 hstore_plpython3u 应该按照文档中的描述转换 hstore to/from python dict,但似乎不起作用。 hstore 变成了一个字符串(似乎没有发生转换)。为什么,以及如何解决它?
The extensions for PL/Python are called hstore_plpythonu, hstore_plpython2u, and hstore_plpython3u (see Section 45.1 for the PL/Python naming convention). If you use them, hstore values are mapped to Python dictionaries. https://www.postgresql.org/docs/current/hstore.html
创建扩展
create extension plpython3u;
create extension hstore_plpython3u;
创建函数
create function type(names hstore)
returns text
language plpython3u as $$
return type(names);
$$;
调用函数
select type(hstore('name','martin'));
returns
type
---------------
<class 'str'>
(1 row)
我想明白了。来自 /contrib/hstore_plpython
中的 expected/hstore_plpython.out
文件:
CREATE FUNCTION test1arr(val hstore[]) RETURNS int
LANGUAGE plpythonu
TRANSFORM FOR TYPE hstore
AS $$
assert(val == [{'aa': 'bb', 'cc': None}, {'dd': 'ee'}])
return len(val)
$$;
SELECT test1arr(array['aa=>bb, cc=>NULL'::hstore, 'dd=>ee']);
test1arr
----------
2