Thread: [BUGS] psql history and "-- lines"
Hello, when I do # psql db=> -- whatever db=> SELECT * FROM x; I expect, that who lines enter the history: "-- whaever" and "SELECT * FROM x;". However, when I press the up-arrow, both lines appear. --single-line does not change this (I wouldn't expect actually). Could you plexe alter psql, so that it logs two lines in the history for the mentioned case? Regards Дилян -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs
Hello,
when I do
# psql
db=> -- whatever
db=> SELECT * FROM x;
I expect, that who lines enter the history: "-- whaever" and "SELECT * FROM x;". However, when I press the up-arrow, both lines appear.
--single-line does not change this (I wouldn't expect actually).
Could you plexe alter psql, so that it logs two lines in the history for the mentioned case?
It probably should only behave as you suggest in --single-line mode...
David J.
"David G. Johnston" <david.g.johnston@gmail.com> writes: > On Fri, May 5, 2017 at 1:52 PM, Дилян Палаузов <dpa-postgres@aegee.org> > wrote: >> Could you plexe alter psql, so that it logs two lines in the history for >> the mentioned case? > It probably should only behave as you suggest in --single-line mode... I'm not exactly convinced that the proposed change would be an improvement. Consider code along the lines of (actual example from system_views.sql): -- -- Redeclare built-in functions that need default values attached to their -- arguments. It's impractical to set those up directly in pg_proc.h because -- of the complexity and platform-dependency of the expression tree -- representation. (Note that internal functions still have to have entries -- in pg_proc.h; we are merely causing their proargnames and proargdefaults -- to get filled in.) -- CREATE OR REPLACE FUNCTION pg_start_backup(label text, fast boolean DEFAULT false, exclusive boolean DEFAULT true) RETURNSpg_lsn STRICT VOLATILE LANGUAGE internal AS 'pg_start_backup' PARALLEL RESTRICTED; Would you really want each of those -- lines to be their own history entry? Another angle to think about is /* ... */ comments, which you really can't break into separate lines without creating a syntactically-invalid mess. That type of comment also creates the possibility of input like /* foo* bar */ select ... There isn't any very nice way to separate this comment from the SQL query for history purposes. In my own usage, I think having leading comments being treated as part of the SQL command is a good thing --- they're sort of a unit, in most cases. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs
Hello, I expect that psql and the shell, e.g. bash, behave in the same way in regards to history logs and until-the-current-line comments. /* such comments * are out of scope */ SELECT 'here'; In bash, when I start typing a line, that I want to execute later, I put # in the beginning of the line, and later I go with C-p to that line. Another possibility to mark the line as comment is with the insert-comment (M-#) readline command/binding, which prepends # the line and generates <RET>. In psql M-# puts also # at the beginning of the line, but this shall be altered to a "--" prefix instead. (To be precise, it inserts the character associated with comment-begin). Fix: diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c --- a/src/bin/psql/input.c +++ b/src/bin/psql/input.c @@ -356,6 +356,7 @@ initializeInput(int flags) /* these two things must be done in this order: */ initialize_readline(); rl_initialize(); + rl_variable_bind("comment-begin", "--"); useHistory = true; using_history(); Both bash and psql append to .bash_history / .psql_history, only when invoked in interactive mode: echo 'echo "X"'| bash # does not alter .bash_history echo 'echo "X"'| bash -i # appends to .bash_history echo "SELECT '1';" | psql # does not amend to .psql_history psql << Z # does not append to .psql_history> SELECT '1';> Z psql -f whatever.sql # does not add to .psql_history psql -c "SELECT '1';" # likewise psql # does add '\i whatever.sql' to .psql_history, not the file content db=> \i whatever.sql db=> \q Concerning the example from system_views.sql, where eight comment lines precede "CREATE OR REPLACE FUNCTION pg_start_backup": I do not want to type eight lines of comments in an interactive shell. In the case, where the comments are yanked from another source, I still want to have each comment line as separate history entry, as this is consistent with how comments are logged in bash and I am used to. Probably /* such things */ can be used to enforce logging with the subsequent command in contrast to "--". Regards Дилян On 05/06/2017 03:25 AM, Tom Lane wrote: > "David G. Johnston" <david.g.johnston@gmail.com> writes: >> On Fri, May 5, 2017 at 1:52 PM, Дилян Палаузов <dpa-postgres@aegee.org> >> wrote: >>> Could you plexe alter psql, so that it logs two lines in the history for >>> the mentioned case? > >> It probably should only behave as you suggest in --single-line mode... > > I'm not exactly convinced that the proposed change would be an > improvement. Consider code along the lines of (actual example > from system_views.sql): > > -- > -- Redeclare built-in functions that need default values attached to their > -- arguments. It's impractical to set those up directly in pg_proc.h because > -- of the complexity and platform-dependency of the expression tree > -- representation. (Note that internal functions still have to have entries > -- in pg_proc.h; we are merely causing their proargnames and proargdefaults > -- to get filled in.) > -- > > CREATE OR REPLACE FUNCTION > pg_start_backup(label text, fast boolean DEFAULT false, exclusive boolean DEFAULT true) > RETURNS pg_lsn STRICT VOLATILE LANGUAGE internal AS 'pg_start_backup' > PARALLEL RESTRICTED; > > Would you really want each of those -- lines to be their own history > entry? > > Another angle to think about is /* ... */ comments, which you really > can't break into separate lines without creating a syntactically-invalid > mess. That type of comment also creates the possibility of input like > > /* foo > * bar */ select ... > > There isn't any very nice way to separate this comment from the SQL query > for history purposes. > > In my own usage, I think having leading comments being treated as > part of the SQL command is a good thing --- they're sort of a unit, > in most cases. > > regards, tom lane > -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs
Дилян Палаузов <dpa-postgres@aegee.org> writes: > I expect that psql and the shell, e.g. bash, behave in the same way in > regards to history logs and until-the-current-line comments. I do not think that the shell necessarily provides a gold-plated precedent for us to follow. The language syntax it's dealing with is substantially different from SQL. Even ignoring that point, there are a lot of shell implementations with a lot of different interactive behaviors; who's to say that bash is the one true way? > + rl_variable_bind("comment-begin", "--"); Interesting thought, but IIUC that's a setting that would be better left to the user's ~/.inputrc, or might indeed override something he's put there. I'm also dubious how well it works across all the versions of readline and libedit that are out there. Perhaps we could document suggested settings for people to put into ~/.inputrc: $if psqlset comment-begin "-- "... other things?$endif regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs
Hello, the comment-begin should be useful in psql, even if the user has not explicitly set comment-begin to be usefull (--): Change comment-begin, if it has the libreadline default value: diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c index 2359b11dcd..93da7f7c75 100644 --- a/src/bin/psql/input.c +++ b/src/bin/psql/input.c @@ -356,6 +356,8 @@ initializeInput(int flags) /* these two things must be done in this order: */ initialize_readline(); rl_initialize(); + if (!strcmp("#", rl_variable_value("comment-begin"))) + rl_variable_bind("comment-begin", "--"); useHistory = true; using_history(); Greetings Дилян On 05/07/2017 01:17 AM, Tom Lane wrote: > Дилян Палаузов <dpa-postgres@aegee.org> writes: >> I expect that psql and the shell, e.g. bash, behave in the same way in >> regards to history logs and until-the-current-line comments. > > I do not think that the shell necessarily provides a gold-plated precedent > for us to follow. The language syntax it's dealing with is substantially > different from SQL. Even ignoring that point, there are a lot of shell > implementations with a lot of different interactive behaviors; who's to > say that bash is the one true way? > >> + rl_variable_bind("comment-begin", "--"); > > Interesting thought, but IIUC that's a setting that would be better left > to the user's ~/.inputrc, or might indeed override something he's put > there. I'm also dubious how well it works across all the versions of > readline and libedit that are out there. > > Perhaps we could document suggested settings for people to put into > ~/.inputrc: > > $if psql > set comment-begin "-- " > ... other things? > $endif > > > regards, tom lane > -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs
Hello, if there is no consensus, on whether --lines should substitute a separate entry in the history, then make it an .psqlrc/CLI option. For psql/HISTSIZE, please update the documentation to state, that HISTSIZE -1 disables the file truncation. About the concerns with rl_variable_bind("comment-begin", "--") regarding libreadline/libedit versions: you can put the change only on master and announce it for Pg10. If nobody objects within a year, this can be backported. Greetings Дилян On 05/07/2017 01:17 AM, Tom Lane wrote: > Дилян Палаузов <dpa-postgres@aegee.org> writes: >> I expect that psql and the shell, e.g. bash, behave in the same way in >> regards to history logs and until-the-current-line comments. > > I do not think that the shell necessarily provides a gold-plated precedent > for us to follow. The language syntax it's dealing with is substantially > different from SQL. Even ignoring that point, there are a lot of shell > implementations with a lot of different interactive behaviors; who's to > say that bash is the one true way? > >> + rl_variable_bind("comment-begin", "--"); > > Interesting thought, but IIUC that's a setting that would be better left > to the user's ~/.inputrc, or might indeed override something he's put > there. I'm also dubious how well it works across all the versions of > readline and libedit that are out there. > > Perhaps we could document suggested settings for people to put into > ~/.inputrc: > > $if psql > set comment-begin "-- " > ... other things? > $endif > > > regards, tom lane > -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs
On 5/6/17 19:17, Tom Lane wrote: >> + rl_variable_bind("comment-begin", "--"); > Interesting thought, but IIUC that's a setting that would be better left > to the user's ~/.inputrc, or might indeed override something he's put > there. I'm also dubious how well it works across all the versions of > readline and libedit that are out there. Hmm, this variable appears with other customization settings, but it's clearly something that is specific to the syntax you are typing in, so pre-setting it makes sense. I think this is something we can play with in PG11. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs