hstore_plperl
在 hstore 和 plperl 之间转换适配类型
概览
版本
| PG18 | PG17 | PG16 | PG15 | PG14 |
|---|
| 1.0 | 1.0 | 1.0 | 1.0 | 1.0 |
安装
提示:这是 PostgreSQL 内核自带的 contrib 扩展
CREATE EXTENSION hstore_plperl;
用法
hstore_plperl: hstore 与 PL/Perl 之间的类型转换
为 PL/Perl 提供 hstore 类型的转换支持。加载后,hstore 值会自动转换为 Perl 哈希,反之亦然。
CREATE EXTENSION hstore_plperl;
CREATE FUNCTION hstore_to_text(val hstore) RETURNS text
LANGUAGE plperl TRANSFORM FOR TYPE hstore AS $$
# val 现在是一个 Perl 哈希引用
my $result = '';
for my $key (sort keys %$val) {
$result .= "$key => $val->{$key}\n";
}
return $result;
$$;
CREATE FUNCTION make_hstore(key text, value text) RETURNS hstore
LANGUAGE plperl TRANSFORM FOR TYPE hstore AS $$
my ($k, $v) = @_;
return { $k => $v };
$$;
SELECT hstore_to_text('a=>1, b=>2'::hstore);
SELECT make_hstore('color', 'blue');