pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephen Frost <sfrost@snowman.net>
To: Ferrell, Denise D CTR NSWCDD, H11 <denise.ferrell.ctr@navy.mil>
Cc: pgsql-admin@postgresql.org <pgsql-admin@postgresql.org>
Subject: Re: Passing parameters
Date: Tue, 22 Mar 2016 10:58:34 -0400
Message-ID: <20160322145834.GA3127@tamriel.snowman.net> (raw)
In-Reply-To: <2BC18916DE4BF141AC1EFC55CE2CAE7D1BBB644F@NAEANRFKXM01V.nadsusea.nads.navy.mil>
References: <2BC18916DE4BF141AC1EFC55CE2CAE7D1BBB644F@NAEANRFKXM01V.nadsusea.nads.navy.mil>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-admin>

Hi Denise!

* Ferrell, Denise D CTR NSWCDD, H11 (denise.ferrell.ctr@navy.mil) wrote:
> Using PostgreSQL v9.3 on Linux Red Hat...
> 
> I've got a script that I'm running from the Linux command prompt that I need to pass 2 parameter's into the psql script without using the VI Editor.  Is there an easy way to accomplish this?
> 
> psql <database> -f <scriptname> -l <log_file>

It really depends on how you want to use the variables in the script.

psql has a '-v' option which you can use to set variables that can be
used with the ':varname' syntax inside of the script, for example:

psql -v table=abc -f script.sql

Inside of script.sql you can then have ':table', like so:

select * from :table;

and that ':table' will be replaced by 'abc' when psql is run with the
'-v table=abc' parameter.

Hope that helps!

Thanks!

Stephen

Attachments:

  signature.asc (application/pgp-signature, 818B) download

view thread (4+ messages)  latest in thread

Message-ID: <20160322145834.GA3127@tamriel.snowman.net>
Permalink:  ../20160322145834.GA3127@tamriel.snowman.net/
Also on:    postgresql.org/message-id/20160322145834.GA3127@tamriel.snowman.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: sfrost@snowman.net, denise.ferrell.ctr@navy.mil
  Subject: Re: Passing parameters
  In-Reply-To: <20160322145834.GA3127@tamriel.snowman.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox