From: | Stephen Frost <sfrost(at)snowman(dot)net> |
---|---|
To: | "Ferrell, Denise D CTR NSWCDD, H11" <denise(dot)ferrell(dot)ctr(at)navy(dot)mil> |
Cc: | "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org> |
Subject: | Re: Passing parameters |
Date: | 2016-03-22 14:58:34 |
Message-ID: | 20160322145834.GA3127@tamriel.snowman.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
Hi Denise!
* Ferrell, Denise D CTR NSWCDD, H11 (denise(dot)ferrell(dot)ctr(at)navy(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Scott Whitney | 2016-03-22 15:01:03 | Re: Passing parameters |
Previous Message | Ferrell, Denise D CTR NSWCDD, H11 | 2016-03-22 14:44:27 | Passing parameters |