Re: Undefined psql variables - Mailing list pgsql-hackers

From Corey Huinker
Subject Re: Undefined psql variables
Date
Msg-id CADkLM=eVx+qOrcFG-ZkPmneMDR+xC9tBjxbkz9oxVW0gmh2s2w@mail.gmail.com
Whole thread Raw
In response to Re: [HACKERS] Undefined psql variables  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Undefined psql variables  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Mon, Jan 23, 2017 at 12:53 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Corey Huinker <corey.huinker@gmail.com> writes:
> I was giving some thought to how psql handles undefined variables.
> I would like an option where either psql can provide an alternate value
> when an undefined variable is referenced, or a way to detect that a
> specific variable is undefined and replace it with a defined variable.

This seems pretty bizarre.  What's the use case?  Why would it not
be better to build the behavior out of other spare parts, along the
lines of COALESCE or perhaps

      \if not defined(x)
      \set x y
      \fi

Obviously the \if stuff is things we don't have yet either, but
it seems less likely to have surprising side-effects.

                        regards, tom lane

In light of the backticks variable expansion thread, I'm reviving this thread in the hopes that a defined()-ish psql function can make it into v10.
It's something that cannot be solved with a query and \gset, so adding it to psql boolean expressions is the only option I can see.



pgsql-hackers by date:

Previous
From: Fabien COELHO
Date:
Subject: Re: Suggested fix for \p and \r in psql
Next
From: Corey Huinker
Date:
Subject: Re: Variable substitution in psql backtick expansion