X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id F012E9DC84E for ; Mon, 16 Jan 2006 11:33:44 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 75029-04 for ; Mon, 16 Jan 2006 11:33:49 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from qtm.net (mummra.qtm.net [216.163.32.14]) by postgresql.org (Postfix) with SMTP id DA70C9DC852 for ; Mon, 16 Jan 2006 11:33:41 -0400 (AST) Received: (qmail 762 invoked from network); 16 Jan 2006 15:32:37 -0000 Received: from unknown (HELO ?192.168.0.101?) (mur@216.163.42.222) by mummra.qtm.net with SMTP; 16 Jan 2006 15:32:37 -0000 Message-ID: <43CBBCD3.80506@endpoint.com> Date: Mon, 16 Jan 2006 10:33:39 -0500 From: Jeff Boes Organization: End Point, Inc. User-Agent: Thunderbird 1.5 (X11/20051201) MIME-Version: 1.0 CC: pgsql-sql@postgresql.org Subject: Re: psql client: technique for applying default values to :variables? References: <43C55316.60403@endpoint.com> <6d8daee30601111551y68b2663ek6484c830f2107bee@mail.gmail.com> <43C910B6.9080904@endpoint.com> <77ABDE37-069C-4467-BF6D-CC0402218BDB@myrealbox.com> In-Reply-To: <77ABDE37-069C-4467-BF6D-CC0402218BDB@myrealbox.com> X-Enigmail-Version: 0.94.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.215 required=5 tests=[AWL=0.026, MISSING_HEADERS=0.189] X-Spam-Score: 0.215 X-Spam-Level: X-Archive-Number: 200601/89 X-Sequence-Number: 23878 Michael Glaesemann wrote: > > On Jan 14, 2006, at 23:54 , Jeff Boes wrote: > >> Tony Wasson wrote: > >> >> Sure, but that was not my question. I want to be able to set the >> variable on the command line, BUT have it default to a value inside >> the SQL script if not present on the command line. > > You could write a wrapper script that would accept a command line > argument and load the file with the appropriate SET statement prepended. Which really gains me nothing over just: $ psql -f myscript.sql -v "MYVAR=${myvar:-default}" The original question was: how can I store the default value in the "myscript.sql" script where it's used, rather than have it in a calling script? The aim here was to put the default in the code, so they would be bound together... -- Jeffery Boes <>< jeff@endpoint.com