Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aiNlX-0000rq-Sr for pgsql-admin@arkaria.postgresql.org; Tue, 22 Mar 2016 14:58:39 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1aiNlX-0000Vt-9N for pgsql-admin@arkaria.postgresql.org; Tue, 22 Mar 2016 14:58:39 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1aiNlW-0000Vm-IM for pgsql-admin@postgresql.org; Tue, 22 Mar 2016 14:58:38 +0000 Received: from tamriel.snowman.net ([2001:4830:167b::11]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aiNlT-0002lF-Mh for pgsql-admin@postgresql.org; Tue, 22 Mar 2016 14:58:37 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id A4A065F794; Tue, 22 Mar 2016 10:58:34 -0400 (EDT) Date: Tue, 22 Mar 2016 10:58:34 -0400 From: Stephen Frost To: "Ferrell, Denise D CTR NSWCDD, H11" Cc: "pgsql-admin@postgresql.org" Subject: Re: Passing parameters Message-ID: <20160322145834.GA3127@tamriel.snowman.net> References: <2BC18916DE4BF141AC1EFC55CE2CAE7D1BBB644F@NAEANRFKXM01V.nadsusea.nads.navy.mil> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="hh4JweDS6K/aOlXZ" Content-Disposition: inline In-Reply-To: <2BC18916DE4BF141AC1EFC55CE2CAE7D1BBB644F@NAEANRFKXM01V.nadsusea.nads.navy.mil> X-Editor: Vim http://www.vim.org/ X-Info: http://www.snowman.net X-Operating-System: Linux/3.13.0-77-generic (x86_64) X-Uptime: 10:55:53 up 28 days, 11:48, 7 users, load average: 0.11, 0.10, 0.12 User-Agent: Mutt/1.5.21 (2010-09-15) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-admin Precedence: bulk Sender: pgsql-admin-owner@postgresql.org --hh4JweDS6K/aOlXZ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Denise! * Ferrell, Denise D CTR NSWCDD, H11 (denise.ferrell.ctr@navy.mil) wrote: > Using PostgreSQL v9.3 on Linux Red Hat... >=20 > I've got a script that I'm running from the Linux command prompt that I n= eed to pass 2 parameter's into the psql script without using the VI Editor.= Is there an easy way to accomplish this? >=20 > psql -f -l 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=3Dabc -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=3Dabc' parameter. Hope that helps! Thanks! Stephen --hh4JweDS6K/aOlXZ Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJW8V2aAAoJEO1sijiDR2RVk/IQAKpLALkx5cnWztwpEXVjC3nG q24aspyfQSaD4aRgHf9F5bKUfyAdXathDa7w4rPM6uhiv9jH2UP8hVEFxe3qlx4g 5aXJ6SdTLs11/bT28qRlaSCNKuE0Y5MXXjdymImP+965/BkUTxYTTAoFsBfBfIfu 5s4pHz7MspiNicpGYH58r2hHpk0uhQTawGPBHRFKI8U6vv2w+WPLh+P+egqyeW+D kPF9mL59QJhpwg2bSTAzCwQqOnkGCebLbH/+vbnyXh2i/XzIx7UNMRD+5RMPV3hd olILZv2Xxu5P54Ip33hbg5Lw3Shcelo9x8VDcbvBodjB7A8rW6aV9XjKbWIn2nQh gAbaV5GpJgHegGZ+A1Ao+b6d20n3jS+3iyzI3nNeRBSJmZEKq3uW9rpUXok0z9Bi CZ56X1B7VMnfWwlazrATd5kGUWGZSUsg/TldYWOrbsvahU5vzjKrY4iLgMzAOtCp 4CluuuV8kD9fwQw/f0GqruscYt0L9JkLPH/yUFE/Hd3Syb3QnbZYipxnhZghOrrO t1MDeViWRXrM/ejbTEQyDSJcSuUob3hxaSakGx0VdwEC+5Lt9RHvEYb2Xhuyu5jx jUTcA8ZQNdqnSJ+Yg3NKkEup62MvGdmjyaFOD0FugS0cYn+6CTJ2BUce5SfIBiTw +vSssxu/tDuC9muS5k4W =qYuO -----END PGP SIGNATURE----- --hh4JweDS6K/aOlXZ--