Pg::hstore(3pm)

Pg::hstore3pm

Perl extension for encoding/decoding postgresql's hstore data type.

Usage

  use Pg::hstore;
  ...
  my $row = $sth->fetchrow_hashref;   #Getting row from DB
  print "hstore data: ", $row->{addinfo}, "\n";
  my $addinfo = Pg::hstore::decode($row->{addinfo});   #Decoding into perl hashref
  #now $addinfo is 1-level hash ref with key->value
  print "addinfo->'full_name' = ", $addinfo->{full_name}, "\n";
  ...
  #Updating hstore. This type of updating can wipe other process work on addinfo field
  $addinfo->{full_name} = "John the ripper";
  $dbh->do("update users set addinfo=? where id=?", undef,
     Pg::hstore::encode($addinfo), 123);

Overview

decode(string)

Decode given HSTORE value. NULL values will be converted to Perl undef; NULL or empty keys will be ignored. Returns hash ref with key => value pairs. Can return undef on internal error. Keys and values will have same UTF8 flag as incoming string.

encode(hashref)

Encodes given hash ref to HSTORE-format string. undef values will be converted to NULL. Empty or undef keys will be ignored. Returns hstore-serialized string. Can return undef on internal error. String will have UTF8 flag ON if any of hashref values have it.

Export

None by default. Can export hstore_encode and hstore_decode subs:

 use Pg::hstore qw/hstore_encode hstore_decode/;

Releases

6 releases since Debian 8 (Jessie); the text changed 5 times.

  1. 8
  2. 9
  3. 10
  4. 11
  5. 12
  6. 13

Bugs

None known. Feel free to clone/contribue from https://bitbucket.org/PSIAlt/p5-pg-hstore

From libpg-hstore-perl 1.06-5 in Debian 13 (Trixie). Parsed by carta from the page's man source.