Bug #62353 | alter table modify column_definition doesn't change former default value | ||
---|---|---|---|
Submitted: | 5 Sep 2011 15:24 | Modified: | 16 Jan 2012 20:47 |
Reporter: | Alberto Massidda | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: DDL | Severity: | S4 (Feature request) |
Version: | 5.1.3 | OS: | Linux (Ubuntu 11.04) |
Assigned to: | CPU Architecture: | Any | |
Tags: | change, column_definition |
[5 Sep 2011 15:24]
Alberto Massidda
[5 Sep 2011 15:26]
Valeriy Kravchuk
What if column was explicitly set to the same value as default, say, to NULL in your example? Should its value be also changed by your ALTER?
[5 Sep 2011 16:41]
Alberto Massidda
>What if column was explicitly set to the same value as default, say, >to NULL in your example? Should its value be also changed by your ALTER? It makes sense, indeed: if you explicitly set by hand that field to a value which, coincidence, is the same as the default then it means that you wanted it to be... the default value. Now, if for some business reason you decide to change the default value of that column you also should make sure that all the rows that had that default value converge to the new default. Otherwise there's the risk that your application may encounter the... "wrong" default value, now knowing how to deal with it or, worse, dealing with it in the wrong way
[6 Sep 2011 8:12]
Valeriy Kravchuk
Can you name any popular RDBMS that implements semantics you described? I do not see anything like that in any published SQL standard I can find (see http://kb.askmonty.org/en/default-clause, http://kb.askmonty.org/en/alter-table-statement#alter-column-set-default-clause etc).
[6 Sep 2011 11:31]
Alberto Massidda
According to http://www.dba-oracle.com/t_oracle_column_default_value.htm , it seems that Oracle did it until 11g: "This optimized behavior differs from earlier releases, when as part of the ALTER TABLE operation Oracle Database updated each row in the newly created column with the default value, and then fired any AFTER UPDATE triggers defined on the table." Even though I admin that I'm not completely sure about what he really means. Apart from that, does it make any difference? I mean, it's a matter of internal data coherence and it's not tied to the stardard or to other available products
[16 Jan 2012 20:46]
Sveta Smirnova
Thank you for the feedback. I think this would be dangerous addition. Anyway if you need such behavior you can manually run query UPDATE table SET field=NEW_DEFAULT WHERE field=OLD_DEFAULT
[16 Jan 2012 20:47]
Sveta Smirnova
This can be verified as feature request though. But I'd prefer to have different kind of ALTER, say, ALTER ... UPDATE DEFAULT