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 -- ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster