SELECT INTO statement in sqlite

Sqlite

Sqlite Problem Overview


Does sqlite support the SELECT INTO statement?

Actually I am trying to save the data in table1 into table2 as a backup of my database before modifying the data.

When I try using the SELECT INTO statement:

SELECT * INTO equipments_backup FROM equipments;

I get a syntax error:

> "Last Error Message:near "INTO":syntax > error".

Sqlite Solutions


Solution 1 - Sqlite

Instead of

SELECT * INTO equipments_backup FROM equipments

try

CREATE TABLE equipments_backup AS SELECT * FROM equipments

Solution 2 - Sqlite

sqlite does not support SELECT INTO.

You can probably use this form instead:

INSERT INTO equipments_backup SELECT * FROM equipments;

Solution 3 - Sqlite

SQlite didn't have INSERT INTO syntax.

In 2019, I use TEMPORARY keyword to create temporary table and INSERT data to temp table:

CREATE TEMPORARY TABLE equipments_backup(field1 TEXT, field2 REAL)
INSERT INTO equipments_backup SELECT field1, field2 FROM equipments

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmonishView Question on Stackoverflow
Solution 1 - Sqliteuser343574View Answer on Stackoverflow
Solution 2 - SqlitenosView Answer on Stackoverflow
Solution 3 - Sqlitesos418View Answer on Stackoverflow