From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | proposal: features for simpler integration psql to bash |
Date: | 2012-05-25 07:36:59 |
Message-ID: | CAFj8pRAuqGvqkfywNwbW0AJfZn0O=LMUNRHziA7yz-yNNW=FOw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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 var1 var2 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
From | Date | Subject | |
---|---|---|---|
Next Message | Magnus Hagander | 2012-05-25 08:04:13 | Re: pg_stat_statments queryid |
Previous Message | Karl Schnaitter | 2012-05-25 06:56:01 | patch: Use pg_mbcliplen for truncation in text-to-name conversion |