You want to use the .import command. For example:
$ cat demotab.txt 44 92 35 94 43 94 195 49 66 28 135 93 135 91 67 84 135 94 $ echo "create table mytable (col1 int, col2 int);" | sqlite3 foo.sqlite $ echo ".import demotab.txt mytable" | sqlite3 foo.sqlite $ sqlite3 foo.sqlite -- Loading resources from /Users/ramanujan/.sqliterc SQLite version 3.6.6.2 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> select * from mytable; col1 col2 44 92 35 94 43 94 195 49 66 28 135 93 135 91 67 84 135 94
Note that this bulk load command is not SQL, but a custom SQLite function. Thus, it has a strange syntax because we pass it through echo to the interactive command line interpreter, sqlite3 .
In PostgreSQL, the equivalent of COPY FROM : http://www.postgresql.org/docs/8.1/static/sql-copy.html
In MySQL, this is LOAD DATA LOCAL INFILE : http://dev.mysql.com/doc/refman/5.1/en/load-data.html
Last: don't forget to be careful with the .separator value. This is a very common problem when doing bulk inserts.
sqlite> .show .separator echo: off explain: off headers: on mode: list nullvalue: "" output: stdout separator: "\t" width:
You must explicitly set the delimiter as a space, tab, or comma before executing .import .
ramanujan Apr 17 '09 at 10:15 2009-04-17 10:15
source share