Skip to content

hstore_plruby

Transform between hstore and Ruby Hashes for PL/Ruby

plruby · Transform between hstore and Ruby Hashes for PL/Ruby

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
3162hstore_plrubyplruby1.0LANGMITC
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-rNoYesNoYesyesno
Extension control default_version is 1.0; shipped in the PL/Ruby 2.5.0 package.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY1.019 18 17 16 15plrubyhstore, plruby
RPMPIGSTY2.5.019 18 17 16 15plruby_$vruby-libs
DEBPIGSTY2.5.019 18 17 16 15postgresql-$v-plruby-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
el8.aarch64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
el9.x86_64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
el9.aarch64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
el10.x86_64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
el10.aarch64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
d12.x86_64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
d12.aarch64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
d13.x86_64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
d13.aarch64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
u22.x86_64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
u22.aarch64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
u24.x86_64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
u24.aarch64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
u26.x86_64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
u26.aarch64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0

Source

pig build pkg plruby;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install plruby;		# install by package name
pig install hstore_plruby;		# install by extension name

pig install hstore_plruby -v 18;   # install for PG 18
pig install hstore_plruby -v 17;   # install for PG 17
pig install hstore_plruby -v 16;   # install for PG 16
pig install hstore_plruby -v 15;   # install for PG 15

Create this extension with:

CREATE EXTENSION hstore_plruby CASCADE; -- requires hstore, plruby

Usage

Sources:

hstore_plruby installs a PostgreSQL transform between hstore and Ruby Hash values for the plruby language. Keys become Ruby strings and values become strings or nil; a compatible Ruby hash can be returned directly as hstore.

Install and Use the Transform

CREATE EXTENSION hstore;
CREATE EXTENSION plruby;
CREATE EXTENSION hstore_plruby;

CREATE FUNCTION ruby_add_hstore_key(hstore)
RETURNS hstore
LANGUAGE plruby
TRANSFORM FOR TYPE hstore
AS $$
  value = args[0]
  value['processed'] = 'yes'
  value
$$;

SELECT ruby_add_hstore_key('id=>42'::hstore);

The transform is used only by functions that declare TRANSFORM FOR TYPE hstore.

Objects and Caveats

  • hstore_to_plruby(internal) implements SQL-to-Ruby conversion.
  • plruby_to_hstore(internal) implements Ruby-to-SQL conversion.
  • The extension version is 1.0, it requires both hstore and plruby, and it is relocatable.
  • hstore is a flat string-to-string-or-NULL map. It does not preserve nested Ruby hashes, arrays, or typed numeric values; use jsonb_plruby when those shapes matter.
  • PL/Ruby remains untrusted. Installing this transform does not sandbox Ruby code or reduce the privileges required to create PL/Ruby functions.

Table reader