Search code examples
sqlsqlitedump

How can I dump data that I want of some SQLite3 tables in SQL format?


I know how to select which table I want to dump in SQL format with the shell command: $ ./sqlite3 test.db '.dump mytable' > test.sql But this command selects all the data of "mytable"

Can I select the data in my table that I want before dump and how? In other terms I seek a command like : $ ./sqlite3 test.db '.dump select name from mytable' > test.sql Obviously this command does not work :'(


Solution

  • The only way to do it within the sqlite console is to create a temporary table:

    CREATE TABLE tmp AS SELECT (field1, field2 ... ) FROM yourTable WHERE ... ;
    .dump tmp
    DROP TABLE tmp