Re: SQL select return into PSQL variables. - Mailing list pgsql-general

From Vick Khera
Subject Re: SQL select return into PSQL variables.
Date
Msg-id 2968dfd61002180748y4b6a13b9wf3f843c69619560@mail.gmail.com
Whole thread Raw
In response to SQL select return into PSQL variables.  ("Little, Douglas" <DOUGLAS.LITTLE@orbitz.com>)
List pgsql-general
On Thu, Feb 18, 2010 at 10:33 AM, Little, Douglas <DOUGLAS.LITTLE@orbitz.com> wrote:

psql

orbitz=# \!testvar=1234

orbitz=# \!export testvar

orbitz=# \!echo $testvar

1234

orbitz=# \q

-bash-3.00$ echo $testvar                                                                                                                                    

1234

What shell are you using that allows a child process to alter the parent process' environment?  ohhhhh. you must be on windows....  this is not normal unix behavior: the child process (psql) cannot alter the parent (shell) environment, and every \! command you run fires a new subshell.  On unix you see this:

[yertle]% psql
Timing is on.
Welcome to psql 8.3.9 (server 8.3.7), the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

khera=> \!testvar=1234
khera=> \!export testvar
khera=> \!echo $testvar

khera=> \q
[yertle]% echo $testvar
testvar: Undefined variable.
[yertle]% 

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Trying to add a type modifier to user created type
Next
From: Carsten Kropf
Date:
Subject: Re: Trying to add a type modifier to user created type