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 C492B9DC985 for ; Wed, 11 Jan 2006 19:50:59 -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 17735-09 for ; Wed, 11 Jan 2006 19:51:02 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.204]) by postgresql.org (Postfix) with ESMTP id 9140C9DC89B for ; Wed, 11 Jan 2006 19:50:57 -0400 (AST) Received: by zproxy.gmail.com with SMTP id 14so292276nzn for ; Wed, 11 Jan 2006 15:51:00 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=dKiliv/TXpnZiae5dn6BsFbawMRQFTAoQpr2w23YNsOQbC9CS3zF5nQyd4z5hg8pW5WiKxiOqqPmaHcmBELc3SmYI4HyrRotiT2KbnSXTM5RwDzGs03Cl7DISGgzf/ut9fFqVKT3RFDBqr48jUGxhvFCcFRMu5EXq8CCwiBcIpc= Received: by 10.36.101.3 with SMTP id y3mr1342506nzb; Wed, 11 Jan 2006 15:51:00 -0800 (PST) Received: by 10.37.14.48 with HTTP; Wed, 11 Jan 2006 15:51:00 -0800 (PST) Message-ID: <6d8daee30601111551y68b2663ek6484c830f2107bee@mail.gmail.com> Date: Wed, 11 Jan 2006 16:51:00 -0700 From: Tony Wasson To: Jeff Boes Subject: Re: psql client: technique for applying default values to :variables? Cc: pgsql-sql@postgresql.org In-Reply-To: <43C55316.60403@endpoint.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <43C55316.60403@endpoint.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.16 required=5 tests=[AWL=0.160] X-Spam-Score: 0.16 X-Spam-Level: X-Archive-Number: 200601/47 X-Sequence-Number: 23836 On 1/11/06, Jeff Boes wrote: > Stumped: is there any way to set up default values for psql variables > within the .SQL file itself? Obviously, I can do something like: > > $ psql -f my_script -v MYVAR=3D${myvar:-mydefault} > > but I would prefer to have the value stored with the .SQL file, e.g. (if > this actually worked): > > \set MYVAR COALESCE(:MYVAR,'mydefault') Stuff like this works for me in a SQL file.... \set edate 'CURRENT_DATE::DATE' SELECT * FROM some_table WHERE update_date =3D :edate;