postgresqlperlplperl

Accessing current_settings function within a plperl function in Postgres


I am writing my first plperl function in Postgres and I have a need to access some values in the current_settings() area (by use of that call) -- and I am wondering what the best solution to doing so is?

In plpgsql I can do something like:

DECLARE
  cid int;
BEGIN
  select nullif(current_setting('jwt.claims.customerId', true), '') :: int into cid;
END ...

Just wondering about the equivalent of accessing system functions like current_setting within a Perl plperl script..

THanks!


Solution

  • Use one of the database access functions, e.g.:

    $rv = spi_exec_query("select nullif(current_setting('jwt.claims.customerId', true), '')::int as cid");
    $cid = $rv->{rows}[0]->{cid};