postgresql - 如何启用 hstore_plpython3u
问题描述
如文档中所述,扩展 hstore_plpython3u 应该将 hstore 转换为 python dict 或从 python dict 转换,但似乎不起作用。hstore 变成一个字符串(似乎没有发生转换)。为什么,以及如何解决?
PL/Python 的扩展名为 hstore_plpythonu、hstore_plpython2u 和 hstore_plpython3u(请参阅第 45.1 节了解 PL/Python 命名约定)。如果使用它们,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)
解决方案
想通了,我想。从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
----------
2
推荐阅读
- python - 如何在 python 中覆盖 1/x 运算符
- matlab - 关于matlab中的泊松生成器poissrnd的问题
- discord.js - 当用户对特定消息做出反应时如何添加角色
- android - 我正在尝试从 Firebase 数据库中的“价格”节点获取值的总和
- react-bootstrap - 无法应用引导程序做出反应(类型无效)
- javascript - 如何存根从另一个函数调用的模块函数
- javascript - 尝试使用 javaScript 制作第二张图片而不是第一张图片
- java - 如何找到这个动态值?如何获取此文本(对我的操作)及其在硒中的动态值
- flutter - 在 Flutter 中处理视频通话状态
- java - 如何在 cs50 的第一个问题集中获得用户的输入?