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 3E1D99DC82A for ; Mon, 16 Jan 2006 13:02:37 -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 91057-03 for ; Mon, 16 Jan 2006 13:02:32 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp2.rz.uni-karlsruhe.de (smtp2.rz.uni-karlsruhe.de [129.13.185.218]) by postgresql.org (Postfix) with ESMTP id 132979DC83F for ; Mon, 16 Jan 2006 13:02:29 -0400 (AST) Received: from rzstud1.stud.uni-karlsruhe.de (rzstud1.stud.uni-karlsruhe.de [193.196.41.33]) by smtp2.rz.uni-karlsruhe.de with esmtp (Exim 4.50 #1) id 1EyXkQ-0002Oq-Eu; Mon, 16 Jan 2006 18:02:26 +0100 Received: from uwi7 by rzstud1.stud.uni-karlsruhe.de with local (Exim 3.36 #1) id 1EyXkQ-00061N-00; Mon, 16 Jan 2006 18:02:26 +0100 From: Andreas Seltenreich To: Jeff Boes 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> <43CBBCD3.80506@endpoint.com> X-PGP-Key: 0x2C006B340F8C8C1B X-Now-Playing: Aphex Twin / Selected Ambient Works II Disc 2 X-Face: $:F<87a[gD1?#R6S3j21cr1&C&7bd63GHC.tSdskUb}hhwG(ci*=D5kJ<_N+p9q(7-, PnG. Et.Yh (Jeff Boes's message of "Mon, 16 Jan 2006 10:33:39 -0500") User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) Message-ID: <87psmsumvy.fsf@gate450.dyndns.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.083 required=5 tests=[AWL=0.083] X-Spam-Score: 0.083 X-Spam-Level: X-Archive-Number: 200601/91 X-Sequence-Number: 23880 Jeff Boes writes: > Michael Glaesemann wrote: >> 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... How about using the traditional Unix macro processor "m4" instead of psql's variables? E.g., you could write a myscript.sql.m4 file with m4 variables instead of psql ones. You could then use ifdef() to test for previous definitions, or even define a default()-wrapper macro. regards, Andreas --