How to assign default values to psql variables?

From: Torsten Förtsch <tfoertsch123(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: How to assign default values to psql variables?
Date: 2017-02-22 05:00:32
Message-ID: CAKkG4_m8xCWC6ZdpVEmFoLGDBt_XtTo_08F+Se2Q3+1=DnzgEA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I have a psql script relying on variables passed in on the command line
with -v.

Is there any way to assign a default value in case the -v option is
forgotten?

Here is an example with pgtap:

select diag('should be printed only in verbose mode') where :testverbose;

This can be called with -v testverbose=true or -v testverbose=false.
However, if the assignment is forgotten, it breaks. I'd like to behave it
as if testverbose=false was passed.

Thanks.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2017-02-22 05:09:44 Re: How to assign default values to psql variables?
Previous Message Adrian Klaver 2017-02-22 00:10:48 Re: bloat indexes - opinion