From: | Corey Huinker <corey(dot)huinker(at)gmail(dot)com> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Undefined psql variables |
Date: | 2017-01-23 17:34:08 |
Message-ID: | CADkLM=eFUs3VHT9tZp_5WEAZoywpV_YF=44KUwKRVf-z=hmsoA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
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.
My first thought thought was to have a
\set_if_undefined var_name 'default_value'
Another idea adding a \pset parameter that would return a specific value
when an undefined psql variable is referenced instead of raising an error.
Like this:
# select :'x' as value_of_x;
ERROR: syntax error at or near ":"
LINE 1: select :'x' as value_of_x;
^
# \pset variable_default ''
analytics=# select :'x' as value_of_x;
value_of_x
------------
(1 row)
# \pset variable_default ''
# select :'x' as value_of_x;
ERROR: syntax error at or near ":"
LINE 1: select :'x' as value_of_x;
^
This would end up having behavior somewhat similar to +e/-e in bash, where
a paranoid script could do something like this:
\pset variable_default 'default1'
select :'required_var1' as required_var1 \gset
\pset variable_default 'default2'
select :'required_var2' as required_var2 \gset
-- reset to default behavior
\pset variable_default error
Thus setting sane defaults to vars that weren't assigned at invocation time.
Thoughts?
From | Date | Subject | |
---|---|---|---|
Next Message | Corey Huinker | 2017-01-23 17:39:32 | Re: proposal: enhanced stack trace for PL - print param args |
Previous Message | David Christensen | 2017-01-23 16:59:32 | Re: Online enabling of page level checksums |