Re: Passing parameters into an in-line psql invocation

From: Bosco Rama <postgres(at)boscorama(dot)com>
To: "Gauthier, Dave" <dave(dot)gauthier(at)intel(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Passing parameters into an in-line psql invocation
Date: 2011-06-02 19:28:22
Message-ID: 4DE7E456.1050700@boscorama.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Gauthier, Dave wrote:
>
> I'd like to pass a parameter into an inline psql call that itself
> calls an sql script, something like...
>
> psql mydb -c "\i thesqlscript foo"
>
> Where"foo" is the value I want to pass in.

You may want to use the --set or --variable options of psql and then
reference the variable name in thesqlscript.

So the psql becomes:
psql --set 'var=foo' -c '\i thesqlscript'

and then in thesqlscript:
update table set column = :var;

HTH

Bosco.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Leif Biberg Kristensen 2011-06-02 19:50:39 Re: Passing parameters into an in-line psql invocation
Previous Message Bosco Rama 2011-06-02 19:21:47 Re: Postgres 8.3.5 - ECPG and the use of descriptors and cursors in multi-threaded programs