Re: psql & unix env variables - Mailing list pgsql-general

From Chris Angelico
Subject Re: psql & unix env variables
Date
Msg-id CAPTjJmrJMvsMga9YFh8C9BzceVDFLW-NdAe8G8J2j=-E14mpsA@mail.gmail.com
Whole thread Raw
In response to Re: psql & unix env variables  (Achilleas Mantzios <achill@smadev.internal.net>)
Responses Re: psql & unix env variables  (Adrian Klaver <adrian.klaver@gmail.com>)
Re: psql & unix env variables  (Achilleas Mantzios <achill@matrix.gatewaynet.com>)
Re: psql & unix env variables  (Achilleas Mantzios <achill@smadev.internal.net>)
List pgsql-general
On Thu, Aug 30, 2012 at 4:42 PM, Achilleas Mantzios
<achill@smadev.internal.net> wrote:
> I have found useful the use of variable assignment in psql, e.g.
>
> #!/bin/sh
>
> # lets say you have some var with a value, or even populate some var with a value from
> # psql as shown below
> somevar=`psql -P pager=off -q -t -c "SELECT foo from bar" | head -1 | sed -e 's/ //g'`
>
> # now use that variable in psql, (what you want to achieve), but in more tight manner
> # than simple shell substitution (see -v switch and : notation)
>
> psql -P pager=off -q -v somevar=$somevar -c "select foo2 from bar2 where var=:somevar"

At this point, I have to ask: Why not switch to a language with actual
Postgres bindings? Try Python, or Pike, or something; I'm sure it's
going to be easier than doing everything through shell scripts.

ChrisA


pgsql-general by date:

Previous
From: Mike Orr
Date:
Subject: Re: Baseline configurations
Next
From: Adrian Klaver
Date:
Subject: Re: psql & unix env variables