Skip to content

jsonb_plpythonu

Transform between JSONB and PL/PythonU values

jsonb_plpythonu · Transform between JSONB and PL/PythonU values

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
101019jsonb_plpythonujsonb_plpythonu1.0LANGUnknownC

PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18

Relationships
Requiresplpythonu

Usage

Sources:

jsonb_plpythonu version 1.0 defines a PostgreSQL transform between jsonb and PL/Python values. Functions that explicitly request TRANSFORM FOR TYPE jsonb receive Python dictionaries, lists, strings, numbers, booleans, or None instead of the default textual representation and can return those values as jsonb.

Transform use

CREATE EXTENSION jsonb_plpythonu CASCADE;
CREATE FUNCTION jsonb_key_count(value jsonb) RETURNS integer
LANGUAGE plpythonu
TRANSFORM FOR TYPE jsonb
AS $$
return len(value)
$$;
SELECT jsonb_key_count('{"a":1,"b":2}'::jsonb);

This exact extension depends on the legacy unversioned plpythonu language and its control/module metadata references the Python-2-era library name. Modern PostgreSQL installations generally use the sibling jsonb_plpython3u variant instead. PL/Python is untrusted, so only superusers can create its functions. The repository has not changed since 2017; verify Python/PostgreSQL ABI compatibility and numeric/container round trips, and do not load the legacy variant merely to run current Python code.

Table reader