[PROPOSAL] Make PSQLVAR on \getenv opitional

Started by Matheus Alcantaraabout 4 years ago7 messages
#1Matheus Alcantara
msalcantara.dev@pm.me

Hi pgsql hackers, I was testing the new psql command \getenv introduced on commit 33d3eeadb2 and from a user perspective, I think that would be nice if the PSQLVAR parameter were optional, therefore when it is only necessary to view the value of the environment variable, the user just run \getenv, for example:

\getenv PATH
/usr/local/sbin:/usr/local/bin:/usr/bin

And when it is necessary to assign the environment variable in a variable, the user could execute like this:

\getenv PATH myvar
\echo :myvar
/usr/local/sbin:/usr/local/bin:/usr/bin

For this flexibility the order of parameters would need to be reversed, instead of \getenv PSQLVAR ENVVAR would be \getenv ENVVAR PSQLVAR.

What do you guys think? I'm not a C expert but if this proposal is interesting I can write a patch.

This is my first time sending an email here, so let me know if I doing something wrong.

#2Pavel Stehule
pavel.stehule@gmail.com
In reply to: Matheus Alcantara (#1)
Re: [PROPOSAL] Make PSQLVAR on \getenv opitional

út 28. 12. 2021 v 19:51 odesílatel Matheus Alcantara <msalcantara.dev@pm.me>
napsal:

Hi pgsql hackers, I was testing the new psql command \getenv introduced on
commit 33d3eeadb2 and from a user perspective, I think that would be nice
if the PSQLVAR parameter were optional, therefore when it is only necessary
to view the value of the environment variable, the user just run \getenv,
for example:

\getenv PATH
/usr/local/sbin:/usr/local/bin:/usr/bin

And when it is necessary to assign the environment variable in a variable,
the user could execute like this:

\getenv PATH myvar
\echo :myvar
/usr/local/sbin:/usr/local/bin:/usr/bin

For this flexibility the order of parameters would need to be reversed,
instead of \getenv PSQLVAR ENVVAR would be \getenv ENVVAR PSQLVAR.

What do you guys think? I'm not a C expert but if this proposal is
interesting I can write a patch.

it is not consistent with other \g* commands. Maybe a new statement \senv
? But what is the use case? You can just press ^z and inside shell write
echo $xxx, and then fg

Regards

Pavel

Show quoted text

This is my first time sending an email here, so let me know if I doing
something wrong.

#3Matheus Alcantara
msalcantara.dev@pm.me
In reply to: Pavel Stehule (#2)
Re: [PROPOSAL] Make PSQLVAR on \getenv opitional

út 28. 12. 2021 v 19:51 odesílatel Matheus Alcantara <msalcantara.dev@pm.me> napsal:

Hi pgsql hackers, I was testing the new psql command \getenv introduced on commit 33d3eeadb2 and from a user perspective, I think that would be nice if the PSQLVAR parameter were optional, therefore when it is only necessary to view the value of the environment variable, the user just run \getenv, for example:

\getenv PATH
/usr/local/sbin:/usr/local/bin:/usr/bin

And when it is necessary to assign the environment variable in a variable, the user could execute like this:

\getenv PATH myvar
\echo :myvar
/usr/local/sbin:/usr/local/bin:/usr/bin

For this flexibility the order of parameters would need to be reversed, instead of \getenv PSQLVAR ENVVAR would be \getenv ENVVAR PSQLVAR.

What do you guys think? I'm not a C expert but if this proposal is interesting I can write a patch.

it is not consistent with other \g* commands. Maybe a new statement \senv ? But what is the use case? You can just press ^z and inside shell write echo $xxx, and then fg

I think that the basic use case would be just for debugging, instead call \getenv and them \echo, we could just use \getenv. I don't see any other advantages, It would just be to
write fewer commands. I think that ^z and then fg is a good alternative, since this behavior would be inconsistent.

Show quoted text

Regards

Pavel

This is my first time sending an email here, so let me know if I doing something wrong.

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Matheus Alcantara (#3)
Re: [PROPOSAL] Make PSQLVAR on \getenv opitional

Matheus Alcantara <msalcantara.dev@pm.me> writes:

it is not consistent with other \g* commands. Maybe a new statement \senv ? But what is the use case? You can just press ^z and inside shell write echo $xxx, and then fg

I think that the basic use case would be just for debugging, instead call \getenv and them \echo, we could just use \getenv. I don't see any other advantages, It would just be to
write fewer commands. I think that ^z and then fg is a good alternative, since this behavior would be inconsistent.

You don't even need to do that much. This works fine:

postgres=# \! echo $PATH

So I'm not convinced that we need another way to spell that.
(Admittedly, this probably doesn't work on Windows, but
I gather that environment variables are less interesting there.)

regards, tom lane

#5Matheus Alcantara
msalcantara.dev@pm.me
In reply to: Tom Lane (#4)
Re: [PROPOSAL] Make PSQLVAR on \getenv opitional

On Tuesday, December 28th, 2021 at 16:53, Tom Lanetgl@sss.pgh.pa.us wrote:

Matheus Alcantara msalcantara.dev@pm.me writes:

it is not consistent with other \g* commands. Maybe a new statement \senv ? But what is the use case? You can just press ^z and inside shell write echo $xxx, and then fg

I think that the basic use case would be just for debugging, instead call \getenv and them \echo, we could just use \getenv. I don't see any other advantages, It would just be to

write fewer commands. I think that ^z and then fg is a good alternative, since this behavior would be inconsistent.

You don't even need to do that much. This works fine:

postgres=# \! echo $PATH

So I'm not convinced that we need another way to spell that.

(Admittedly, this probably doesn't work on Windows, but

I gather that environment variables are less interesting there.)

regards, tom lane

I definitely agree with this. We already have other ways to handle it.

Thanks for discussion and quick responses.

Matheus Alcantara

#6Andrew Dunstan
andrew@dunslane.net
In reply to: Tom Lane (#4)
Re: [PROPOSAL] Make PSQLVAR on \getenv opitional

On 12/28/21 14:53, Tom Lane wrote:

Matheus Alcantara <msalcantara.dev@pm.me> writes:

it is not consistent with other \g* commands. Maybe a new statement \senv ? But what is the use case? You can just press ^z and inside shell write echo $xxx, and then fg

I think that the basic use case would be just for debugging, instead call \getenv and them \echo, we could just use \getenv. I don't see any other advantages, It would just be to
write fewer commands. I think that ^z and then fg is a good alternative, since this behavior would be inconsistent.

You don't even need to do that much. This works fine:

postgres=# \! echo $PATH

So I'm not convinced that we need another way to spell that.
(Admittedly, this probably doesn't work on Windows, but
I gather that environment variables are less interesting there.)

I haven't tested, but I'm fairly sure

postgres=# \! echo %PATH%

would do the trick on Windows.

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

#7Christoph Moench-Tegeder
cmt@burggraben.net
In reply to: Pavel Stehule (#2)
Re: [PROPOSAL] Make PSQLVAR on \getenv opitional

## Pavel Stehule (pavel.stehule@gmail.com):

it is not consistent with other \g* commands. Maybe a new statement \senv
? But what is the use case? You can just press ^z and inside shell write
echo $xxx, and then fg

That does not work: backgrounding psql will put you into your original
shell, the parent process of psql. Changes in the environment of a
process do not change the environment of the parent.
Use \! to start a new shell process from psql, which will inherit psql's
environment.

Regards,
Christoph

--
Spare Space