Re: libpq environment variables in the server

From: ilmari(at)ilmari(dot)org (Dagfinn Ilmari Mannsåker )
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: Noah Misch <noah(at)leadboat(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: libpq environment variables in the server
Date: 2019-03-15 10:06:29
Message-ID: d8j4l845u56.fsf@dalvik.ping.uio.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> writes:

> On 2019-03-15 05:00, Noah Misch wrote:
>> I consider the following style more idiomatic:
>>
>> {
>> local %ENV;
>> delete $ENV{PGAPPNAME};
>> ...
>> }
>
> That doesn't work because the first line clears the entire environment.

The solution to that is to do 'local %ENV = %ENV;', to assign a copy of
the original to the localised variable. This doesn't work on VMS,
because its concept of environment variables is quite different from
UNIX, but PostgreSQL doesn't support that anyway.

> What does work is
>
> {
> delete local $ENV{PGAPPNAME};
> ...
> }
>
> But that is documented as new in Perl 5.12.0, so we might not be able to
> use it. It appears to work in the 5.8.9 I have lying around, so I'm
> confused.

It "works" as in it's not a syntax error, but it doesn't actually
localise the deletion. The following program:

use strict;
use warnings;
use feature 'say';

our %env = qw(foo bar baz bat);
say "original: ", join(", ", sort keys %env);
{
delete local $env{foo};
say "localised: ", join(", ", sort keys %env);
}
say "restored? ", join(", ", sort keys %env);

on 5.12 prints:

original: baz, foo
localised: baz
restored? baz, foo

while on 5.10 it prints:

original: baz, foo
localised: baz
restored? baz

BTW, https://perl.bot/ is handy for testing things like this on various
Perl versions you don't have lying around.

- ilmari
--
- Twitter seems more influential [than blogs] in the 'gets reported in
the mainstream press' sense at least. - Matt McLeod
- That'd be because the content of a tweet is easier to condense down
to a mainstream media article. - Calle Dybedahl

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Steele 2019-03-15 10:07:14 Re: Re: Re: [HACKERS] Custom compression methods
Previous Message Michael Paquier 2019-03-15 09:58:56 Re: Offline enabling/disabling of data checksums