Subject | Re: [firebird-support] Firebird 2.5 - Alter table - drop default - bug or feature |
---|---|
Author | Svein Erling Tysvær |
Post date | 2017-04-25T14:24:06Z |
Hi everyone,I encountered strange behavior droping a column definition with default value.The environment is Ubuntu 16.04 LTS 64 bits, Firebird version LI-V2.5.6.27020 (Firebird 2.5 SuperClassic)I'll try to explain with an example. The statement sequence is:1. Create the tableCREATE TABLE "SCHEMA_AUTHOR" ("ID" integer NOT NULL PRIMARY KEY, "NAME" varchar(255) NOT NULL, "HEIGHT" integer CHECK ("HEIGHT" >= 0))2. Popultate with some dataINSERT INTO SCHEMA_AUTHOR (ID, NAME, HEIGHT) VALUES ('1', 'Anonimus1', NULL);3. Alter the tableALTER TABLE "SCHEMA_AUTHOR" ADD "SURNAME" varchar(15) DEFAULT 'surname default' NOT NULLAfter step 3, I have a record with a new column with 'surname default' value into SURNAME field.4. Drop default definitionALTER TABLE "SCHEMA_AUTHOR" ALTER COLUMN "SURNAME" DROP DEFAULTAfter step 4, the SURNAME field value is setting to empty string ('')Is that the correct behavior ?I think you're wrong in assuming that the record after step 3 contains 'surname default'. Please tryselect iif( "SURNAME" is null, 'I'm empty', 'I contain a value')from SCHEMA_AUTHORafter step 3. I don't use Firebird 3 myself, but I'd be greatly surprised if they'd changed so that existing records got default values when defining the default values. Also, take a look at this old document: https://firebirdsql.org/manual/nullguide-alter-pop-tables.html.Basically, what you should do is to add another step after step 3:UPDATE SCHEMA_AUTHORSET "SURNAME" = 'surname default';HTH,Set