[HACKERS] Undefined psql variables

Поиск
Список
Период
Сортировка
От Corey Huinker
Тема [HACKERS] Undefined psql variables
Дата
Msg-id CADkLM=eFUs3VHT9tZp_5WEAZoywpV_YF=44KUwKRVf-z=hmsoA@mail.gmail.com
обсуждение исходный текст
Ответы Re: [HACKERS] Undefined psql variables  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: [HACKERS] Undefined psql variables  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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?

В списке pgsql-hackers по дате отправления:

Предыдущее
От: David Christensen
Дата:
Сообщение: Re: [HACKERS] Online enabling of page level checksums
Следующее
От: Corey Huinker
Дата:
Сообщение: Re: [HACKERS] proposal: enhanced stack trace for PL - print param args