Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc2f6549

Browse files
committed
psql: treat "--" comments between queries as separate history entries.
If we've not yet collected any non-whitespace, non-comment token for anew query, flush the current input line to history before readinganother line. This aligns psql's history behavior with the observationthat lines containing only comments are generally not thought of asbeing part of the next query. psql's prompting behavior is consistentwith that view, too, since it won't change the prompt until youenter something that's neither whitespace nor a "--" comment.Greg Nancarrow, simplified a bit by meDiscussion:https://postgr.es/m/CAJcOf-cAdMVr7azeYR7nWKsNp7qhORzc84rV6d7m7knG5Hrtsw@mail.gmail.com
1 parent8388468 commitc2f6549

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

‎src/bin/psql/mainloop.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,20 @@ MainLoop(FILE *source)
564564
break;
565565
}
566566

567-
/* Add line to pending history if we didn't execute anything yet */
568-
if (pset.cur_cmd_interactive&& !line_saved_in_history)
569-
pg_append_history(line,history_buf);
567+
/*
568+
* Add line to pending history if we didn't do so already. Then, if
569+
* the query buffer is still empty, flush out any unsent history
570+
* entry. This means that empty lines (containing only whitespace and
571+
* perhaps a dash-dash comment) that precede a query will be recorded
572+
* as separate history entries, not as part of that query.
573+
*/
574+
if (pset.cur_cmd_interactive)
575+
{
576+
if (!line_saved_in_history)
577+
pg_append_history(line,history_buf);
578+
if (query_buf->len==0)
579+
pg_send_history(history_buf);
580+
}
570581

571582
psql_scan_finish(scan_state);
572583
free(line);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp