Re: psql & unix env variables

From: Achilleas Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: psql & unix env variables
Date: 2012-08-31 09:29:08
Message-ID: 1494985.CJ8A5OchKv@smadev.internal.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Παρ 31 Αυγ 2012 09:19:26 Chris Angelico wrote:
> On Thu, Aug 30, 2012 at 4:42 PM, Achilleas Mantzios
> <achill(at)smadev(dot)internal(dot)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.
>

or perl, or php, or java, etc...
actually we "switched" to java some 11 years ago to build our infrastructure,
but occasionally (or not so occasionally, but rather being part of the architecture)
still sh/bach/tcsh/perl are heavily used and have their place.
Its all about taste/preference and not easily jumping into overkill mode.

OTOH the OP asked for doing exactly what -v (--set) var assignments are supposed to do.
(lift shell substitution ambiguities about escaping and var expansion)

> ChrisA
>
>
>
-
Achilleas Mantzios
IT DEPT

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Achilleas Mantzios 2012-08-31 09:29:24 Re: psql & unix env variables
Previous Message Achilleas Mantzios 2012-08-31 09:03:25 Re: psql & unix env variables