24.03.2017 09:33, Vlad Khorsun wrote:
>
>> Firebird is known to upgrade the record format while reading. "Upgrade"
>> here means using the latest (aka current) format. The current format is
>> the one that can be seen in RDB$RELATION_FIELDS. So one may expect that
>> the default value to be used is also the latest one, that's stored in
>> RDB$ tables. IIRC, this is how FB 2.5 works.
>
> Exactly. When i read the table and know that some field should have default
> value, i expect to see this value at system catalog.

It depends on the definition. In fact, adding a NOT NULL DEFAULT X 
column means two things: (1) DEFAULT X will be used implicitly for 
inserts or explicitly for the DEFAULT keyword and (2) X will be used to 
replace the missing values. For (1), everything works as expected. For 
(2), your expectation relies on the fact that X is substituted while 
reading. But this is just an implementation detail. The contract is 
"replacing missing values", whatever it could mean. Someone else does 
not know such internals and expects this "replacement" happening by some 
voodoo magic during ALTER ;-)

Also, lets consider this:

SQL> create table t (col1 int);
SQL> insert into t values (1);
SQL> commit;
SQL> alter table t add col2 int default 123 not null;
SQL> select * from t;

         COL1         COL2
============ ============
            1          123

SQL> alter table t alter col2 drop default;
SQL> select * from t;

         COL1         COL2
============ ============
            1          123

There's no default at the end, but COL2 is still returning 123. This 
matches the "update" expectation, not the "convert missing to the 
current default" one.

Yesterday I considered this issue being a bug, but now I'm not that 
sure. It may look obvious for some users but counter-intuitive for the 
others.

Anyone outside the development team cares to comment? :-)


Dmitry


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to