pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Seltenreich <andreas+pg@gate450.dyndns.org>
To: Jeff Boes <jeff@endpoint.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: psql client: technique for applying default values to :variables?
Date: Mon, 16 Jan 2006 18:02:25 +0100
Message-ID: <87psmsumvy.fsf@gate450.dyndns.org> (raw)
In-Reply-To: <43CBBCD3.80506@endpoint.com>
References: <43C55316.60403@endpoint.com>
	<6d8daee30601111551y68b2663ek6484c830f2107bee@mail.gmail.com>
	<43C910B6.9080904@endpoint.com>
	<77ABDE37-069C-4467-BF6D-CC0402218BDB@myrealbox.com>
	<43CBBCD3.80506@endpoint.com>

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
-- 



view thread (6+ messages)

Message-ID: <87psmsumvy.fsf@gate450.dyndns.org>
Permalink:  ../87psmsumvy.fsf@gate450.dyndns.org/
Also on:    postgresql.org/message-id/87psmsumvy.fsf@gate450.dyndns.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: andreas+pg@gate450.dyndns.org, jeff@endpoint.com
  Subject: Re: psql client: technique for applying default values to :variables?
  In-Reply-To: <87psmsumvy.fsf@gate450.dyndns.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox