Skip to content

hstore_plperl

transform between hstore and plperl

plperl · transform between hstore and plperl

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
3262hstore_plperlplperl1.0LANGPostgreSQLC
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-rNoYesNoYesyesno

Packages

PG19PG18PG17PG16PG15
1.01.01.01.01.0
This contrib extension ships with PostgreSQL.

Install

Create this extension with:

CREATE EXTENSION hstore_plperl CASCADE; -- requires hstore, plperl

Usage

hstore_plperl: Transform between hstore and PL/Perl

Provides a transform for the hstore type for PL/Perl. When loaded, hstore values are automatically converted to Perl hashes and vice versa.

CREATE EXTENSION hstore_plperl;

CREATE FUNCTION hstore_to_text(val hstore) RETURNS text
LANGUAGE plperl TRANSFORM FOR TYPE hstore AS $$
  # val is now a Perl hash reference
  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');

Table reader