扩展hstore_plpython3u应该像文档中所描述的那样,将hstore转换为/从python,但似乎不起作用。hstore变成一个字符串(似乎没有发生转换)。为什么,怎么解决呢?
PL/Python的扩展称为hstore_plpythonu、hstore_plpython2u和hstore_plpython3u (关于PL/Python命名约定,请参阅45.1节)。如果使用它们,hstore值将映射到Python字典。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'));返回
type
---------------
<class 'str'>
(1 row)发布于 2021-06-16 18:03:25
我想应该是。来自expected/hstore_plpython.out文件中的/contrib/hstore_plpython
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
----------
2https://stackoverflow.com/questions/68007690
复制相似问题