Default non-NULL values copied from a column that was added using "ALTER
TABLE ... ADD COLUMN ... DEFAULT ..." are inserted into another table as
NULLs when copied using "INSERT INTO ... SELECT * FROM ..."

However, the same values are propagated correctly when "CREATE TABLE ... AS
SELECT * FROM ..." is executed.

See example below:

$ sqlite3
SQLite version 3.8.4.3 2014-04-03 16:53:12
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .header on
sqlite> .mode column
sqlite> CREATE TABLE a(a);
sqlite> INSERT INTO a VALUES(1);
sqlite>
sqlite> ALTER TABLE a ADD COLUMN b DEFAULT 2;
sqlite>
sqlite> CREATE TABLE b AS SELECT * FROM a;
sqlite> INSERT INTO  b    SELECT * FROM a;
sqlite>
sqlite> SELECT * FROM a;
a           b
----------  ----------
1           2
sqlite> SELECT * FROM b;
a           b
----------  ----------
1           2
1
sqlite>

-- 

This message contains confidential information and is intended only for the 
individual named. If you are not the named addressee, you should not 
disseminate, distribute, alter or copy this e-mail. Please notify the 
sender immediately by e-mail if you have received this e-mail by mistake 
and delete this e-mail from your system. E-mail transmissions cannot be 
guaranteed to be secure or without error as information could be 
intercepted, corrupted, lost, destroyed, or arrive late or incomplete. The 
sender, therefore, does not accept liability for any errors or omissions in 
the contents of this message which arise during or as a result of e-mail 
transmission. If verification is required, please request a hard-copy 
version. This message is provided for information purposes and should not 
be construed as a solicitation or offer to buy or sell any securities or 
related financial instruments in any jurisdiction.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to