pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedpsql > split > queries & output
6+ messages / 3 participants
[nested] [flat]
* psql > split > queries & output
@ 2020-12-03 11:38 Wim Bertels <wim.bertels@ucll.be>
2020-12-03 12:33 ` Re: psql > split > queries & output Pavel Stehule <pavel.stehule@gmail.com>
2020-12-03 14:18 ` Re: psql > split > queries & output Daniel Verite <daniel@manitou-mail.org>
0 siblings, 2 replies; 6+ messages in thread
From: Wim Bertels @ 2020-12-03 11:38 UTC (permalink / raw)
To: pgsql-general
Hello,
psql shows (the queries and) the output,
there are for example the -L option and echo_queries option
is there a way to run psql so that:
* inside psql there are no surprises :) (ignore this line:)
* one pipe (or..) to a file which only contains the statements
(queries) history (and not the output)
* another pipe (or..) to a file which only contains the output (with or
without the statements) history
why? for example,
to have easy access in a psql demonstration to past commands
(history),
without the output cluttering or overwhelming everything, side by side
on the screen. (optionally with a third pane for the output)
there is also the /s option in psql,
but i guess the history is only written to file when psql is closed,
and is not accessible during the session (only in memory?),
otherwise this would also be an option
(not ctrl+r)
suggestions or alternatives while using the commandline?
--
mvg,
Wim
--
https://coronalert.be
--
Always do right. This will gratify some people and astonish the rest.
-- Mark Twain
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: psql > split > queries & output
2020-12-03 11:38 psql > split > queries & output Wim Bertels <wim.bertels@ucll.be>
@ 2020-12-03 12:33 ` Pavel Stehule <pavel.stehule@gmail.com>
1 sibling, 0 replies; 6+ messages in thread
From: Pavel Stehule @ 2020-12-03 12:33 UTC (permalink / raw)
To: wim.bertels@ucll.be; +Cc: pgsql-general
čt 3. 12. 2020 v 12:39 odesílatel Wim Bertels <wim.bertels@ucll.be> napsal:
> Hello,
>
> psql shows (the queries and) the output,
> there are for example the -L option and echo_queries option
>
> is there a way to run psql so that:
> * inside psql there are no surprises :) (ignore this line:)
> * one pipe (or..) to a file which only contains the statements
> (queries) history (and not the output)
> * another pipe (or..) to a file which only contains the output (with or
> without the statements) history
>
> why? for example,
> to have easy access in a psql demonstration to past commands
> (history),
> without the output cluttering or overwhelming everything, side by side
> on the screen. (optionally with a third pane for the output)
>
> there is also the /s option in psql,
> but i guess the history is only written to file when psql is closed,
> and is not accessible during the session (only in memory?),
> otherwise this would also be an option
> (not ctrl+r)
>
> suggestions or alternatives while using the commandline?
>
Unfortunately it is not possible. Both contents are sent to stdout. The
own hack can be pretty easy, but without it it is not possible.
Regards
Pavel
> --
> mvg,
> Wim
> --
> https://coronalert.be
>
>
> --
> Always do right. This will gratify some people and astonish the rest.
> -- Mark Twain
>
>
>
>
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: psql > split > queries & output
2020-12-03 11:38 psql > split > queries & output Wim Bertels <wim.bertels@ucll.be>
@ 2020-12-03 14:18 ` Daniel Verite <daniel@manitou-mail.org>
2020-12-03 15:20 ` Re: psql > split > queries & output Wim Bertels <wim.bertels@ucll.be>
1 sibling, 1 reply; 6+ messages in thread
From: Daniel Verite @ 2020-12-03 14:18 UTC (permalink / raw)
To: wim.bertels@ucll.be; +Cc: pgsql-general
Wim Bertels wrote:
> * one pipe (or..) to a file which only contains the statements
> (queries) history (and not the output)
> * another pipe (or..) to a file which only contains the output (with or
> without the statements) history
Consider that script:
$ cat f.sql
\set ECHO queries
\o output.txt
select 1;
select 2;
select 3;
If it's run with
$ psql -f f.sql >queries.txt
then it produces the queries in queries.txt and the output in output.txt
Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: https://www.manitou-mail.org
Twitter: @DanielVerite
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: psql > split > queries & output
2020-12-03 11:38 psql > split > queries & output Wim Bertels <wim.bertels@ucll.be>
2020-12-03 14:18 ` Re: psql > split > queries & output Daniel Verite <daniel@manitou-mail.org>
@ 2020-12-03 15:20 ` Wim Bertels <wim.bertels@ucll.be>
2020-12-03 15:32 ` Re: psql > split > queries & output Daniel Verite <daniel@manitou-mail.org>
0 siblings, 1 reply; 6+ messages in thread
From: Wim Bertels @ 2020-12-03 15:20 UTC (permalink / raw)
To: Daniel Verite <daniel@manitou-mail.org>; +Cc: pgsql-general
Daniel Verite schreef op do 03-12-2020 om 15:18 [+0100]:
> Wim Bertels wrote:
>
> > * one pipe (or..) to a file which only contains the statements
> > (queries) history (and not the output)
> > * another pipe (or..) to a file which only contains the output
> > (with or
> > without the statements) history
>
> Consider that script:
>
> $ cat f.sql
> \set ECHO queries
> \o output.txt
> select 1;
> select 2;
> select 3;
>
> If it's run with
>
> $ psql -f f.sql >queries.txt
>
> then it produces the queries in queries.txt and the output in
> output.txt
thank you,
i use the same with a input file,
but interactively this doesn't seem to work
ie
psql > queries.txt (does not work (stdout))
(psql 2> queries.txt does work (stderr))
(psql &> queries.txt does not work (both))
--
psql -f - > out
does work interactively,
but no fun experience :) (no completion, and the separation does not
seem to work)
>
>
> Best regards,
--
mvg,
Wim
--
https://coronalert.be
--
If you laid all of our laws end to end, there would be no end.
-- Mark Twain
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: psql > split > queries & output
2020-12-03 11:38 psql > split > queries & output Wim Bertels <wim.bertels@ucll.be>
2020-12-03 14:18 ` Re: psql > split > queries & output Daniel Verite <daniel@manitou-mail.org>
2020-12-03 15:20 ` Re: psql > split > queries & output Wim Bertels <wim.bertels@ucll.be>
@ 2020-12-03 15:32 ` Daniel Verite <daniel@manitou-mail.org>
2020-12-04 10:09 ` Re: psql > split > queries & output Wim Bertels <wim.bertels@ucll.be>
0 siblings, 1 reply; 6+ messages in thread
From: Daniel Verite @ 2020-12-03 15:32 UTC (permalink / raw)
To: wim.bertels@ucll.be; +Cc: pgsql-general
Wim Bertels wrote:
> but interactively this doesn't seem to work
Interactively something like this might do the job:
$ PSQL_HISTORY=/tmp/queries.txt psql -L /tmp/logfile.txt
After running some queries, and a clean exit from psql:
$ cat /tmp/queries.txt
select 1;
select 2;
$ cat /tmp/logfile.txt
********* QUERY **********
select 1;
**************************
?column?
----------
1
(1 row)
********* QUERY **********
select 2;
**************************
?column?
----------
2
(1 row)
Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: https://www.manitou-mail.org
Twitter: @DanielVerite
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: psql > split > queries & output
2020-12-03 11:38 psql > split > queries & output Wim Bertels <wim.bertels@ucll.be>
2020-12-03 14:18 ` Re: psql > split > queries & output Daniel Verite <daniel@manitou-mail.org>
2020-12-03 15:20 ` Re: psql > split > queries & output Wim Bertels <wim.bertels@ucll.be>
2020-12-03 15:32 ` Re: psql > split > queries & output Daniel Verite <daniel@manitou-mail.org>
@ 2020-12-04 10:09 ` Wim Bertels <wim.bertels@ucll.be>
0 siblings, 0 replies; 6+ messages in thread
From: Wim Bertels @ 2020-12-04 10:09 UTC (permalink / raw)
To: Daniel Verite <daniel@manitou-mail.org>; +Cc: pgsql-general
Daniel Verite schreef op do 03-12-2020 om 16:32 [+0100]:
> Wim Bertels wrote:
>
> > but interactively this doesn't seem to work
>
> Interactively something like this might do the job:
>
> $ PSQL_HISTORY=/tmp/queries.txt psql -L /tmp/logfile.txt
>
> After running some queries, and a clean exit from psql:
yes indeed,
but as i mentioned in the beginning,
i can't consult the current history in a side pane,
only with option /s
(while still running the psql session)
(side note:
$ echo $PSQL_HISTORY (is empty)
$ psql
psql (12.5 (Debian 12.5-1.pgdg100+1))
Type "help" for help.
# \set HISTFILE /tmp/test
# select 1;
has no effect, /tmp/test is not created,
everything is put into ~.psql_history )
(debian specific?, intended?, or bug?)
>
> $ cat /tmp/queries.txt
> select 1;
> select 2;
>
>
> $ cat /tmp/logfile.txt
> ********* QUERY **********
> select 1;
> **************************
>
> ?column?
> ----------
> 1
> (1 row)
>
> ********* QUERY **********
> select 2;
> **************************
>
> ?column?
> ----------
> 2
> (1 row)
>
>
> Best regards,
--
mvg,
Wim
--
https://coronalert.be
--
In India, "cold weather" is merely a conventional phrase and has come into
use through the necessity of having some way to distinguish between weather
which will melt a brass door-knob and weather which will only make it mushy.
-- Mark Twain
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2020-12-04 10:09 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-12-03 11:38 psql > split > queries & output Wim Bertels <wim.bertels@ucll.be>
2020-12-03 12:33 ` Pavel Stehule <pavel.stehule@gmail.com>
2020-12-03 14:18 ` Daniel Verite <daniel@manitou-mail.org>
2020-12-03 15:20 ` Wim Bertels <wim.bertels@ucll.be>
2020-12-03 15:32 ` Daniel Verite <daniel@manitou-mail.org>
2020-12-04 10:09 ` Wim Bertels <wim.bertels@ucll.be>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox