SQLite

View Ticket
Login
Ticket Hash: f67b41381acce9a881fb081c4a20ecbeb2429b0d
Title: "INSERT INTO tbl SELECT * FROM tbl2" statement may modify data if ALTER TABLE ADD COLUMN has been used on tbl2.
Status: Fixed Type: Code_Defect
Severity: Critical Priority: Immediate
Subsystem: Unknown Resolution: Fixed
Last Modified: 2014-04-26 17:52:31
Version Found In:
User Comments:
dan added on 2014-04-26 12:18:25:

If an "ALTER TABLE ... ADD COLUMN ..." statement is used to add a column to an existing table, the existing table entries are not modified. Instead, it is assumed that any fields missing from the end of such records take the default values for their respective columns.

The following bug is caused by copying such records to a different table with different default values:

SQLite version 3.8.5 2014-04-25 14:42:17
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> CREATE TABLE t1(a);        
sqlite> INSERT INTO t1 VALUES(1);    
sqlite> ALTER TABLE t1 ADD COLUMN b DEFAULT 2;
sqlite> CREATE TABLE t2(a, b);
sqlite> INSERT INTO t2 SELECT * FROM t1;
sqlite> SELECT * FROM t2;
1|
sqlite> SELECT * FROM t1;            
1|2
sqlite> 


dan added on 2014-04-26 12:36:53:
Introduced by [9f56a878cbbc7152]. First released in 3.3.14.