Subject Re: [firebird-support] Raising the scale of a NUMERIC field
Author Ann Harrison
On Mon, Oct 29, 2012 at 12:20 PM, Mark Rotteveel <mark@...>wrote:


> > BUT I'm 100% sure that all the existing data would perfectly fit in
> > (15,8) so, the question is: In this case, is it safe to make the
> > change direct in the system table?
> >
> > update RDB$FIELDS set
> > RDB$FIELD_SCALE = -8
> > where RDB$FIELD_NAME = 'RDB$nnnn';
>
> No, a direct system table update like that would rescale all your existing
> numbers. Eg from (15,4) to (15,8) a value 54321.1234 would become
> 5.43211234
>
> Firebird stores NUMERIC (and DECIMAL) as an INT (or BIGINT or SMALLINT)
> and the scale is used to decide the position of the decimal.
>

Ah, you've missed the magic of formats. Every record version is stored with
a format version number. Every time a table changes shape - meaning a
column is added, dropped, or altered in length or scale, Firebird stores a
new format version for the table with the new physical description. A
transaction asks for a record in a particular format. Firebird does what
is necessary to convert the format it finds to the requested format. On
update, a the record is stored in the newest format. So 54321.1234 would
become 54321.12340000.
The new format is created when a change to the system tables is committed.
In V3.0, your mileage will change.

Cheers,

Ann


[Non-text portions of this message have been removed]