41

I'm following a beginners tutorial to sqlite3. The first step is creating a new database. So I enter a name (movies.db).

I'm expecting to get another sqlite> prompt on the next line, and continue with the tutorial, but instead I get a lame ...> after which I can type any gibbersish I want. Clearly, this is not good.

What my command prompt looks like:

SQLite version 3.8.1 2013-10-17 12:57:35
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> $ sqlite3 movies.db
   ...> gibberish
   ...> dsds
   ...> sdada
   ...> gfgys
   ...> a
   ...> Aaaaarrrgh!
   ...>

How do I get sqlite3 to work normally for me?

Pardon my newbie-ness. I hope I've phrased this question in a way that might help other newbs too.

5
  • 3
    Did you see the part there were it mentioned something about entering an SQL statement ... terminated with a semi-colon ";". The new prompt indicator is for continuation lines.
    – scottb
    Commented Oct 31, 2013 at 15:48
  • 1
    Actually it doesn't say to put a semi-colon. zetcode.com/db/sqlite/tool Commented Oct 31, 2013 at 15:55
  • I apologize for the simple question. The tutorial I am using stinks. I will find a new one. Commented Oct 31, 2013 at 15:56
  • Your tutorial is fine. All you need to do is issue the sqlite3 movies.db command from your system command line – not the Sqlite shell. Have a look the answers below – they will be helpful in your understanding.
    – zeantsoi
    Commented Oct 31, 2013 at 16:07
  • 3
    gibberish was deprecated in version 3.8.1.
    – Pyderman
    Commented May 11, 2016 at 23:27

6 Answers 6

32

Sqlite is working normally. However, the sqlite movies.db command should be issued from your system command line – not from the Sqlite interactive shell. Start by exiting the Sqlite interactive shell (.exit), then issuing the database creation command.

According to the quickstart documentation:

  1. At a shell or DOS prompt, enter: "sqlite3 test.db". This will create a new database named "test.db". (You can use a different name if you like.)

  2. Enter SQL commands at the prompt to create and populate the new database.

Once the sqlite movies.db command is properly executed from your system command line, you'll automatically be placed in the Sqlite interactive shell, which will be awaiting commands.

sqlite> create table tbl1(one varchar(10), two smallint);

The ...> shell prompt indicates a continuance from the preceding line. As indicated in the message, you'll need to terminate each database command with a ; semicolon.

sqlite> CREATE TABLE tbl2 (
   ...>   f1 varchar(30) primary key,
   ...>   f2 text,
   ...>   f3 real
   ...> );
sqlite>
15

Terminate the statement with a ;. So just hit ; then enter and it will go back to normal (after giving an error, because what you've typed here is bad sql).

What's going on is it thinks you are still working on something. It can be useful to break up long queries into lines like this:

sqlite> select title, description
   ...> from mytable
   ...> where id > 10;

And the ...> means it is waiting for you to finish your query, which you signify with the semicolon.

4
  • 9
    > Terminate the statement with a ;. So just hit ; then enter and it will go back to normal (after giving an error, because what you've typed here is bad sql). This isn't true, at least not for version 3.7.11. Semicolon throws you right back at the ...> prompt (only ctrl-z works to escape). Maybe it's a bug?
    – weberc2
    Commented Jan 29, 2015 at 17:23
  • 2
    Encountering this as well. Sometimes ')' then enter, followed by ';' and enter, does the trick.
    – Pyderman
    Commented May 11, 2016 at 23:27
  • 1
    If you are inside a string, you need '; o r";.
    – CL.
    Commented Apr 28, 2018 at 6:43
  • 1
    This is quite horrible. At least it should close with cmd+c/ctrl+c. Commented Apr 17, 2019 at 10:17
11

I constantly hit up arrow or left arrow and get into this below. I've found that only control-D works.

sqlite> ^[[A
   ...> '
   ...> ;
   ...> 
   ...> ;
   ...> 
   ...> 
   ...> 
   ...> 
   ...> ^C
   ...> ^X
   ...> 
   ...> 
   ...> 
   ...> 
   ...> 
   ...> 
   ...> ^E
   ...> ^R

   ...> ^T
   ...> ^Y
   ...> ^K
   ...> ^X
   ...> quit
   ...> '
   ...> ;
   ...> /
   ...> g
   ...> 
   ...> 
   ...> .exit
   ...> )
   ...> ;
   ...> /
   ...> ;
   ...> /
   ...> /
   ...> /
   ...> /
   ...> /
   ...> /
   ...> /
   ...> /
   ...> /
   ...> /
   ...> /
   ...> >
   ...> ;
   ...> /
   ...> '/
   ...> ;
   ...> ,
   ...> ;
   ...> ^[[D
   ...> /
   ...> .quit
   ...> ∂
'  ...> Error: incomplete SQL: 
2
  • 2
    control-z moves the process to the background. it is still running.
    – brando
    Commented Jul 15, 2017 at 2:27
  • CTRL-D will exit sqlite3. If you are running from command line this environment is volatile, so you will loose everything and have to start over.
    – Dave
    Commented Jun 25, 2021 at 1:27
2

If you enter of any of these by mistake - ^[[A^[[A^[[B, then simply press ];

Closing the bracket followed by a semicolon does the trick.

1

I got in the same state after hitting some arrow keys

sqlite> ^[[A^[[A^[[B
   ...> ;
   ... 30 more lines of randomly-typed unsuccessful characters ...
   ...> /
sqlite>

The forward-slash character '/' seemed to solve it for me.

1

(I know this is an old question but this still seems to be an issue with the SQLite command-line interface and I have had the same problem recently.)

...> is called the continuation prompt in the SQLite command-line interface.

There is no standard method to get out of it in all cases without also getting out of the interface itself if you got into it unintentionally. If you don't mind getting out of the interface as well, you can just press Ctrl+D.

If you wish to exit the continuation prompt at once but not the interface, first try simply typing a semicolon ; and pressing enter because all SQL statements are supposed to end with a semicolon in the command-line interface. Without the semicolon or a syntax error, the interface thinks you are continuing to enter a command.

It is also possible that the continuation prompt is triggered by a missing closing apostrophe ', quotation mark ", or a right square bracket ]. So type any of these at the continuation prompt followed by a semicolon ; and press enter.

If none of the above works, try triggering a quick syntax error by typing any character between two apostrophes or quotation marks followed by a semicolon such as 'x'; or "x"; or just a forward slash / and pressing enter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.