Subject Re: [Firebird-Architect] NUMERIC vs DECIMAL
Author Ivan Prenosil
> From: "Pavel Cisar"
> On 6 Aug 2003 at 6:56, Claudio Valderrama C. wrote:
>
> > - Both numeric and decimal behave the same. Numeric isn't SQL compliant
> > currently.
> >
> > - For both dialects, being "p" the precision, the internal storage is:
> > 1 <= p <= 4 => smallint
>
> Are you sure ? I'd swear that decimal is stored as INTEGER (32bit) as
> documented. I checked that some time ago on FB 1.0.2 (? don't remember,
> but I'd also swear this apply to both dialects). But my memory is often
> lousy, so the reality check is needed.

Pavel is right. Simple test reveals that SHORT is used only for NUMERIC(<=4,x), not for DECIMAL:

CREATE TABLE T(
D4 DECIMAL(4,1),
N4 NUMERIC(4,2),
D5 DECIMAL(5,3),
N5 NUMERIC(5,4),
D10 DECIMAL(10,5),
N10 NUMERIC(10,6) );

COMMIT;

SELECT
RF.rdb$field_name,
rdb$field_type,
(SELECT RDB$TYPE_NAME FROM RDB$TYPES WHERE RDB$FIELD_NAME='RDB$FIELD_TYPE' AND RDB$TYPE=F.RDB$FIELD_TYPE),
rdb$field_scale,
rdb$field_length
FROM RDB$RELATION_FIELDS RF JOIN RDB$FIELDS F ON RF.RDB$FIELD_SOURCE=F.RDB$FIELD_NAME
WHERE RDB$RELATION_NAME='T';


RDB$FIELD_NAME RDB$FIELD_TYPE RDB$FIELD_SCALE RDB$FIELD_LENGTH
=============== ============== =========== =============== ================
D4 8 LONG -1 4
N4 7 SHORT -2 2
D5 8 LONG -3 4
N5 8 LONG -4 4
D10 16 INT64 -5 8
N10 16 INT64 -6 8

And for dialect-1:
D10 27 DOUBLE -5 8
N10 27 DOUBLE -6 8


Ivan