From c472ca83b98aea8f7617094cb9786bac615218d6 Mon Sep 17 00:00:00 2001 From: Shivam Maurya <156692956+shivampwm2020@users.noreply.github.com> Date: Fri, 16 Oct 2026 02:29:28 +0530 Subject: [PATCH] fix: do not offer SQL completions after the statement terminator The trailing ';' of a statement is annotated as sql_garbage and the SQL completion trigger in rl_sql_change() did not exclude that annotation. Once the schema is known, typing the same statement a second time leaves a completion popup open on the terminator, so Enter accepts the suggestion instead of executing the query. Skip completion when the attribute under the cursor is sql_garbage. Fixes #1751 --- src/readline_callbacks.cc | 11 ++++++----- test/test_sql_anno.sh | 5 +++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/readline_callbacks.cc b/src/readline_callbacks.cc index e4b2223a9b..2353ef93cd 100644 --- a/src/readline_callbacks.cc +++ b/src/readline_callbacks.cc @@ -760,11 +760,12 @@ rl_sql_change(textinput_curses& rc, bool is_req) if (!is_req && attr_iter->sa_type == &SQL_HEX_LIT_ATTR && attr_iter->sa_range.length() == 2) { - } else if (is_req - || (attr_iter->sa_type != &SQL_NUMBER_ATTR - && attr_iter->sa_type != &SQL_HEX_LIT_ATTR) - || rc.tc_popup_type - == textinput_curses::popup_type_t::completion) + } else if (attr_iter->sa_type != &SQL_GARBAGE_ATTR + && (is_req + || (attr_iter->sa_type != &SQL_NUMBER_ATTR + && attr_iter->sa_type != &SQL_HEX_LIT_ATTR) + || rc.tc_popup_type + == textinput_curses::popup_type_t::completion)) { auto to_complete_sf = anno_line.to_string_fragment(attr_iter); diff --git a/test/test_sql_anno.sh b/test/test_sql_anno.sh index 93244ea470..3d4c25c172 100644 --- a/test/test_sql_anno.sh +++ b/test/test_sql_anno.sh @@ -124,3 +124,8 @@ take 10 run_cap_test ./drive_sql_anno "SELECT * FROM customers LIMIT 1" run_cap_test ./drive_sql_anno "SELECT * FROM customers FULL JOIN all_logs pg_stmt_log ON (pg_stmt_log.log_text LIKE '%STATEMENT:%') LIMIT 1" + +# the trailing ';' must be annotated as garbage so that the SQL completion +# trigger in rl_sql_change() does not offer suggestions at the statement +# terminator (see #1751) +run_cap_test ./drive_sql_anno "SELECT * FROM caddy_log WHERE 1=1;"