Re: passing linux user to PG server as a variable ?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: David Gauthier <davegauthierpg(at)gmail(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: passing linux user to PG server as a variable ?
Date: 2020-08-17 20:07:35
Message-ID: CAKFQuwYEPDGPueKmG6vK5Lpk3HzOHV=3ypH-En48wW0rKL7ErQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Aug 17, 2020 at 12:53 PM David Gauthier <davegauthierpg(at)gmail(dot)com>
wrote:

> Looking at psql command line options, I see "-v" (lowercase) which is
> described as...
>
> -v assignment
> --set=assignment
> --variable=assignment
>
> Perform a variable assignment, like the \set meta-command. Note that you
> must separate name and value, if any, by an equal sign on the command line.
> To unset a variable, leave off the equal sign. To set a variable with an
> empty value, use the equal sign but leave off the value. These assignments
> are done during a very early stage of start-up, so variables reserved for
> internal purposes might get overwritten later.
> So I tried that without success. "-v sysinfo.osuser=foo" failed the
> connect with..."psql: could not set variable "sysinfo.osuser""
>
> Next I tried..."-v osuser=foo"This didn't fail the connect, but once I
> got in..."show osuser" gave... "ERROR: unrecognized configuration
> parameter "osuser""
>
The part of the description that says "like the \set meta-command" means
you need to read its description as well. There, and through links
therein, you will learn that what you are creating is a variable within the
psql client itself, not on the server. Usage of that client-side variable
is documented. As long as you don't need the variable on the server, and
oftentimes you do not, then this feature will work just fine for you.

The SHOW SQL command (and other documented options[1]) is a server command
and inspects server variables. If you really need to create one of those
in the current session it may be possible - though I believe you have to
use a namespace prefix (i.e., your sysinfo.osuser) to get the system to
recognize a user-created variable name. There is some work on improving
things in this area. Though worse case you can just stick the desired
value into a temporary table and maybe create some function wrappers to
modify/access it.

David J.

[1] https://www.postgresql.org/docs/devel/config-setting.html

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Gauthier 2020-08-17 21:27:10 Re: passing linux user to PG server as a variable ?
Previous Message Tim Clarke 2020-08-17 20:05:52 Re: passing linux user to PG server as a variable ?