proposal: features for simpler integration psql to bash

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема proposal: features for simpler integration psql to bash
Дата
Msg-id CAFj8pRAuqGvqkfywNwbW0AJfZn0O=LMUNRHziA7yz-yNNW=FOw@mail.gmail.com
обсуждение исходный текст
Список pgsql-hackers
Hello

we don't have a macro language in psql. I did some work few years ago
- see enhanced psql - http://postgres.cz/wiki/Enhanced-psql but
important part of this  experimental patch was not accepted
(implementation was not in production quality code and was not
finalized).

Implementation of own macro language is relative difficult - execution
in psql is complex because there is support for interactive multiline
editing, there is support for history, ... actually  we can use a lot
of accessible languages  - so any new interpret is not necessary.
Interesting feature should better integration psql to bash,
possibility to call bash scripts like custom backslash statements and
similar. I have idea about following features:

a) new output format that support simple result's reading in bash

I would to simplify code:

pavel ~ $ psql postgres -A -t --field-separator=" " \  -c "copy (select 1,'Ahoj Svete', i               from
generate_series(1,3)g(i))        to stdout delimiter ' '" | \while read var1 var2 var3;do   echo
"a=$var1,b=$var2,c=$var3";done
 

to

pavel ~ $ psql postgres --format=bash \  -c "select 1,'Ahoj Svete', i from generate_series(1,3) g(i)) '" | \while read
var1var2 var3;do   echo "a=$var1,b=$var2,c=$var3 ";done
 

b) possibility to store query result in psql variables

\execute [query] into var1, var2, var


c) enhancing communication protocol for support access to client and
system variables

We have well implementation of plpgsql - but usage of this language is
difficult for scripting - there are no simple way how to parametrize
code execution - I believe so we can solve this issue with following
functions:

* set_client_variable(varname, value)
* set_client_system_variable(varname, value)
* get_client_variable(varname, value)
* get_client_system_variable(varname, value)

these functions will be executed on server, but it enable access to
client information and configuration - and enable simple
parametrization of DO statement (via psql variables).

What do you think about these ideas?

Regards

Pavel Stehule


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

Предыдущее
От: Karl Schnaitter
Дата:
Сообщение: patch: Use pg_mbcliplen for truncation in text-to-name conversion
Следующее
От: Magnus Hagander
Дата:
Сообщение: Re: pg_stat_statments queryid