diff options
Diffstat (limited to 'src/pl/plperl/input/plperl_env.source')
-rw-r--r-- | src/pl/plperl/input/plperl_env.source | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/pl/plperl/input/plperl_env.source b/src/pl/plperl/input/plperl_env.source new file mode 100644 index 00000000000..8fe526e1b8b --- /dev/null +++ b/src/pl/plperl/input/plperl_env.source @@ -0,0 +1,52 @@ +-- +-- Test the environment setting +-- + +CREATE FUNCTION get_environ() + RETURNS text[] + AS '@libdir@/regress@DLSUFFIX@', 'get_environ' + LANGUAGE C STRICT; + +-- fetch the process environment + +CREATE FUNCTION process_env () RETURNS text[] +LANGUAGE plpgsql AS +$$ + +declare + res text[]; + tmp text[]; + f record; +begin + for f in select unnest(get_environ()) as t loop + tmp := regexp_split_to_array(f.t, '='); + if array_length(tmp, 1) = 2 then + res := res || tmp; + end if; + end loop; + return res; +end + +$$; + +-- plperl should not be able to affect the process environment + +DO +$$ + $ENV{TEST_PLPERL_ENV_FOO} = "shouldfail"; + untie %ENV; + $ENV{TEST_PLPERL_ENV_FOO} = "testval"; + my $penv = spi_exec_query("select unnest(process_env()) as pe"); + my %received; + for (my $f = 0; $f < $penv->{processed}; $f += 2) + { + my $k = $penv->{rows}[$f]->{pe}; + my $v = $penv->{rows}[$f+1]->{pe}; + $received{$k} = $v; + } + unless (exists $received{TEST_PLPERL_ENV_FOO}) + { + elog(NOTICE, "environ unaffected") + } + +$$ LANGUAGE plperl; |