On Sep 27, 2008, at 7:13 AM, Mark Wyszomierski wrote: > Hi, > > I'm trying to add a timestamp field to an existing table using the > following > statement: > > ALTER TABLE test ADD COLUMN lunchtime TIMESTAMP NOT NULL DEFAULT > CURRENT_TIME > > this fails with the following error: > > Cannot add a column with non-constant default > > Ok that makes sense - but why can we CREATE a table with a timestamp > field > whose default is CURRENT_TIME, but not alter one with that as the > default > value? I may be misusing the syntax -
SQLite doesn't modify the underlying table structure when you add a column using ALTER TABLE. So after the ALTER TABLE is executed, the existing rows now contain one value less than the table has columns. When SQLite reads the table, it detects the short row and returns the default column value in place of any missing values. This wouldn't work with something like CURRENT_TIME. > Thanks, > Mark > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users