I made a mistake writing a command at the SQLite command prompt, which I now want to abort, this is how my command line looks

sqlite> select * from todos'
   ...> '
   ...> ;^C

In this case, likely because I have opened a quote, I can't even hit ENTER to run the command. I just get a line continuation, that would still be less than ideal because I would be having to run bad code and cause and error, just to regain control of the prompt.
How can I cancel the line/command and get returned back to a prompt?

  • Maybe ^D will close stdin for sqlite and make it exit... – Ralph Rönnquist Jun 21 '16 at 8:49
  • 1
    @Ralph ctrl D makes sqlite exit the entire session, including losing any in memory databases - if you hapoen to be running any. – the_velour_fog Jun 21 '16 at 8:53

The sqlite3 interface uses the ReadLine library for command line editing. You can erase a full line with Ctrl+U but once you have pressed Enter, the line has been accepted and is no longer editable (well, it is, but not as part of the current statement).

As you've noticed, sending end-of-file with Ctrl+D will prompt the client to exit, which is not what you want.

Your best bet is to

  1. close any string, and then,
  2. before issuing a final ;, generate a syntax error.

In your example:

sqlite> select * from todos'
   ...> '
   ...> *** I made a mistake
   ...> ;
Error: near "*": syntax error

This will ensure that nothing gets executed, and it will leave you in the SQLite session with any temporary tables intact.

  • thanks, yes I thought that might be best workaround – the_velour_fog Jun 21 '16 at 9:30
  • If you have pressed enter after an arrow key, i.e., you have something like > ^[[A and then ...>, then you have to close the brackets to cancel that: > ]];. It really should support Ctrl+C for this. It's obnoxious this way. – mxmlnkn Sep 22 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.