Skip to content

hstore_plpython3u

transform between hstore and plpython3u

plpython3u · transform between hstore and plpython3u

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
3293hstore_plpython3uplpython3u1.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_plpython3u CASCADE; -- requires hstore, plpython3u

Usage

hstore_plpython3u: Transform between hstore and PL/Python3

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

CREATE EXTENSION hstore_plpython3u;

CREATE FUNCTION hstore_to_pairs(val hstore) RETURNS text
LANGUAGE plpython3u TRANSFORM FOR TYPE hstore AS $$
  # val is now a Python dict
  return ', '.join(f'{k}={v}' for k, v in sorted(val.items()))
$$;

CREATE FUNCTION make_hstore(key text, value text) RETURNS hstore
LANGUAGE plpython3u TRANSFORM FOR TYPE hstore AS $$
  return {key: value}
$$;

SELECT hstore_to_pairs('a=>1, b=>2'::hstore);
SELECT make_hstore('color', 'blue');

Table reader