SlideShare a Scribd company logo
www.firebase.com.br 1 © 2014 – Carlos H. Cantu 
Understanding Numbers in Firebird 
Carlos H. Cantuwww.firebase.com.br 
www.firebirdnews.org
www.firebase.com.br 2 © 2014 – Carlos H. Cantu 
Who am I? 
• 
Maintainer of www.firebase.com.br and www.firebirdnews.org 
• 
Author of 2 Firebird books published in Brazil 
• 
Software developer for about 30 years 
• 
Organizer of the Firebird Developers Day conference 
• 
Firebird consultant
www.firebase.com.br 3 © 2014 – Carlos H. Cantu 
Do you wannago crazy?!
www.firebase.com.br 4 © 2014 – Carlos H. Cantu 
Warnings! 
1. 
Internal storage type depends on database dialect 
2. 
The dialect has influence in the precision of some types and in the results of calculations 
3. 
Depending on the datatypeused, the retrieved value can be different from the original value!! 
4. 
Decimal separator is always the dot “.”
www.firebase.com.br 5 © 2014 – Carlos H. Cantu 
INTEGER types 
• 
SMALLINT 
– 
16 bits 
– 
between -32.768 and32.767 
• 
INTEGER 
– 
32 bits 
– 
between -2.147.483.648 and 2.147.483.647 
• 
BIGINT 
– 
64 bits 
– 
between -9.223.372.036.854.775.808 and 9.223.372.036.854.775.807 
– 
Only available in dialect 3
www.firebase.com.br 6 © 2014 – Carlos H. Cantu 
FLOATING POINT types 
• 
FLOAT 
– 
32 bits: 1 for signal, 8 for exponent and 23 for the mantissa. 
– 
7 digits of precision 
– 
Between -3.4 x 1038and 3.4 x 1038 
• 
DOUBLE PRECISION 
– 
64 bits: 1 for signal, 11 for exponent and 52 for the mantissa. 
– 
15 digits of precision 
– 
Between -1.7 x 10308and 1.7 x 10308
www.firebase.com.br 7 © 2014 – Carlos H. Cantu 
Pros and cons of floating types 
• 
Stored following the standard defined by the IEEE (Institute of Electrical and Electronics Engineers), with an approximated representation of the real number. 
• 
Calculations uses the math co-processor (faster). 
• 
Not recommended due to lack of precision.
www.firebase.com.br 8 © 2014 – Carlos H. Cantu 
Accuracy in FLOAT/DOUBLE (1/2) 
SQL> select cast(1234567.1234 as float) from rdb$database; 
CAST 
============== 
1234567.1 
Result displayed by IBExpert: 
1234567.125
www.firebase.com.br 9 © 2014 – Carlos H. Cantu 
Imprecision in FLOAT/DOUBLE (2/2) 
SQL> select cast(1234567.4321 as float) from rdb$database; 
CAST 
============== 
1234567.4 
Result displayed by IBExpert: 
1234567.375
www.firebase.com.br 10 © 2014 – Carlos H. Cantu 
Fixed point 
• 
NUMERIC (p,s) / DECIMAL (p,s) 
• 
Is stored occupying either 16, 32 or 64 bits 
• 
p= precision (total digits) [1 <= p <= 18] s= scale (number of digits after the “comma”) 
• 
smust be always lower or equal to p 
• 
If pand sis not informed, the internal type will be INTEGER 
• 
In FB, palways determinates the minimum number of stored digits (not follow the standard) 
• 
The retrieved value is always exactly equal to the original value!
www.firebase.com.br 11 © 2014 – Carlos H. Cantu 
Internal storage of NUMERIC and DECIMAL 
PRECISION 
INTERNAL TYPE 
DIALECT 3 
DIALECT 1 
1..4 
NUMERIC 
SMALLINT (*) 
SMALLINT 
1..4 
DECIMAL 
INTEGER (*) 
INTEGER 
5..9 
NUMERIC e DECIMAL 
INTEGER 
INTEGER 
10..18 
NUMERIC e DECIMAL 
BIGINT 
DOUBLE PRECISION(!) 
In Firebird, DECIMAL andNUMERICsare thesamething, ifp < 10. 
(*) In this case, the range of supported values are different compared to NUMERIC and DECIMAL
www.firebase.com.br 12 © 2014 – Carlos H. Cantu 
Determining the capacity of chosen numeric/decimals 
1. 
Check the internal type used depending on the precision (p) of the field. 
2. 
Check the range of values supported by the internal type. 
3. 
Divide the min and max values by 10s to know the effective range of accepted values for the field.
www.firebase.com.br 13 © 2014 – Carlos H. Cantu 
Determining the capacity of chosen numeric/decimals 
Example: 
1. 
NUMERIC (9,2) or DECIMAL (9,2) 
2. 
Internally stored as INTEGER 
3. 
Integer = -2.147.483.648 to 2.147.483.647 
4. 
As s = 2, divide by 102 
5. 
Accepted range for a field declared as NUMERIC/DECIMAL (9,2) = -21.474.836,48 to 21.474.836,47
www.firebase.com.br 14 © 2014 – Carlos H. Cantu 
Testing the limits of numeric/decimal 
SQL> select cast(-21474836.48 as numeric (9,2)), cast(-21474836.48 as decimal (9,2)) from rdb$database; 
CAST CAST 
============ ============ 
-21474836.48 -21474836.48 
SQL> select cast(-21474836.49as numeric (9,2)), cast(-21474836.49as decimal (9,2)) from rdb$database; 
CAST CAST 
============ ============ 
Statement failed, SQLSTATE = 22003 
arithmetic exception, numeric overflow, or string truncation 
-numeric value is out of range
www.firebase.com.br 15 © 2014 – Carlos H. Cantu 
Testing the limits of numeric/decimal 
SQL> select cast(32768 as decimal(4,0)) from rdb$database; --integer 
CAST 
============ 
32768 
SQL> select cast(32768 as numeric(4,0)) from rdb$database; --smallint 
CAST 
======= 
Statement failed, SQLSTATE = 22003 
arithmetic exception, numeric overflow, or string truncation 
-numeric value is out of range
www.firebase.com.br 16 © 2014 – Carlos H. Cantu 
Moving from dialect 1 to 3 
• 
Is there any field declared as NUMERIC or DECIMALwith p > 9? 
– 
No: there will be no problem at all 
– 
Yes: you may have problems! 
• 
NUMERIC and DECIMAL with p > 9 are stored as double precision in dialect 1 and the existing fields will stay like this if the DB is “migrated” to dialect 3 using gfix-sql_dialect3. 
• 
New fields declared as NUM/DEC with p > 9, created after the DB was converted to dialect 3 will use BIGINTinternally. 
• 
Recommended solution: create a new DB using a script and pump the data from old to new database.
www.firebase.com.br 17 © 2014 – Carlos H. Cantu 
Integer divisions 
• 
Dialect 1, dividing intby intresults in double precisionI.e.: 1/3 = 0,3333333333333 
• 
Dialect 3, divide intby intresults in integerI.e.: 1/3 = 0
www.firebase.com.br 18 © 2014 – Carlos H. Cantu 
Division/Multiplication of fixed point numerics 
• 
In dialect 1, the division will always return a double precision. 
• 
In dialect 3, the result will be a type withp= 18 and s= sum of the scales of the involved types. 
SQL> select cast(0.33 as numeric (9,2))/ cast (1 as numeric(9,2)) from rdb$database; 
DIVIDE 
===================== 
0.3300
www.firebase.com.br 19 © 2014 – Carlos H. Cantu 
Division/Multiplication of fixed point numerics 
SQL> select (3.00/1.00*3.5)*2.00as totalfrom rdb$database; 
TOTAL 
===================== 
21.0000000 
SQL> select (3.00/1.00/3.5)/2.00as totalfrom rdb$database; 
TOTAL 
===================== 
0.4285700
www.firebase.com.br 20 © 2014 – Carlos H. Cantu 
Division/Multiplication of fixed point numerics 
• 
There can be overflows, specially with calculations involving multiple arguments! 
select cast(1 as numeric(15,6))* cast(1 as numeric(9,8)) * 
cast(1 as numeric(15,5)) from rdb$database 
~ 1.000000* 1.00000000* 1.00000 
Integer overflow. The result of an integer operation caused the most significant bit of the result to carry.
www.firebase.com.br 21 © 2014 – Carlos H. Cantu 
Addition/Subtraction of fixed point numbers 
• 
Result will have sequal the biggest scale of the bigger member of the operation. 
• 
In dialect 1, result will always have p= 9 
• 
In dialect 3, result will always have p= 18 
SQL> select cast(1 as numeric(9,2)) + 
cast(2 as integer) from rdb$database; 
ADD 
===================== 
3.00 
SQL> select cast(0.5 as numeric(9,2)) – 
cast(1 as numeric(9,3)) from rdb$database; 
SUBTRACT 
===================== 
-0.500
www.firebase.com.br 22 © 2014 – Carlos H. Cantu 
Tips summary 
• 
Always create the database in dialect 3, and connect to it using the same dialect. 
• 
For “monetary” fields, choose numericor decimalto guarantee the accuracy. 
• 
When need to store numbers with variable scale (s), choose double precision. 
• 
To migrate a DB from dialect 1 to 3, prefers to PUMP the data instead of using gfix. 
• 
Take care with overflows in calculations involving numeric/decimal.
www.firebase.com.br 23 © 2014 – Carlos H. Cantu 
Curiosities 
INDEXES 
• 
Numbers are stored in keys as double precision (exception to the rule is BIGINT) 
• 
Pros: 
– 
For numeric/decimal, allows changing p or s without needing to reindex 
– 
For smallint/integer, allows converting between the types or to a type having a scale (s) without need to reindex 
• 
Obs: Due to lack of precision of the double precision, the search if done in an interval between the bigger previous value and the lower next value related to the searched value. 
GENERATORS 
• 
Dialect 1 = integer 
• 
Dialect 3 = bigint
www.firebase.com.br 24 © 2014 – Carlos H. Cantu 
Curiosities (do you wannago more crazy??) 
CHECK CONSTRAINTS and CLIENT DIALECTS 
The rules applied by a check constraint are based on the dialect used by the client connection in the time the constraint was created. 
Ex: check (int1 / int2) > 0.5 (rule created with dialect 1 connection) 
When connecting to the DB using dialect 3: 
Insert ... (int1, int2) values (2, 3); --Success! ~ 0.66666666 
Ex: check (int1 / int2) > 0.5 (rule created with dialect 3 connection) 
Insert ... (int1, int2) values (2, 3); --FAILURE! ~ 0
www.firebase.com.br 25 © 2014 – Carlos H. Cantu 
Changing the scale of numeric/decimal fields 
• 
Raising the scale means shortening the range of accepted values 
I.e.: 
numeric (9,2): range -21.474.836,48 to21.474.836,47 
numeric (9,3): range -2.147.483,648 to2.147.483,647 
This operation is not defined for system tables. Unsuccessful metadata update. New scale specified for column AFIELD must be at most 2.
www.firebase.com.br 26 © 2014 – Carlos H. Cantu 
Changing the scale of numeric/decimal fields 
• 
Changing the scale of (9,2) to 3. 
• 
Solutions: 
– 
Create new field declared as (9,3) 
– 
Copy the values to the new field 
– 
Drop the old field 
– 
Rename the new field as the old one 
• 
Changing to (10,3) 
– 
Problem if there are indexes defined for that field, since the internal type changes to bigint!
www.firebase.com.br 27 © 2014 – Carlos H. Cantu 
Changing the scale of numeric/decimal fields 
create table test (afield numeric (9,2)); 
commit; 
insert into test values (10.12); commit; alter table test alter afield type numeric (9,3); 
This operation is not defined for system tables. Unsuccessful metadata update. New scale specified for column AFIELD must be at most 2. 
alter table test alter afield type numeric (10,3); commit; 
update test set afield = 10.123; commit; 
select afield from test; commit; 
Result:10.123
www.firebase.com.br 28 © 2014 – Carlos H. Cantu 
Changing the scale of numeric/decimal fields 
alter table test 
alter afieldtype numeric (10,2); commit; 
select afield from test; 
commit; 
Result:10.12 
alter table test 
alter afield type numeric (11,3); commit; 
select afield from test; 
commit; 
Result:10.123
www.firebase.com.br 29 © 2014 – Carlos H. Cantu 
Changing the scale of numeric/decimal fields 
alter table test alter afield type numeric (10,2); commit; 
select afield from test; commit; 
Result:10.12 
/* “Dumb” Update */ 
update test set afield = afield; commit; 
alter table test 
alter afield type numeric (11,3); commit; 
select afield from test; commit; 
Result:10.120
www.firebase.com.br 30 © 2014 – Carlos H. Cantu 
Changing the scale of numeric/decimal fields 
“Hardcore” solution: 
update RDB$FIELDS setRDB$FIELD_SCALE = -3where RDB$FIELD_NAME = 'RDB$nnn'; 
Warning! 
• 
Be sure that the existing values “fits” in the new range, otherwise some records will be inaccessible(corruption). 
• 
Will not work in Firebird 3!
www.firebase.com.br 31 © 2014 – Carlos H. Cantu 
Additional attention! 
• 
When changing the “size” of an existing field, it can be identified with a different type by the “language/access technology” used in the client application.
www.firebase.com.br 32 © 2014 – Carlos H. Cantu 
Roudings 
• 
Firebird uses “standard rounding”: -Chose what digit will be the limit-Add 1 if the next digit is >= 5-Don’t change the digit if the next is < 5 
I.e.: 
select cast(123.45 as numeric (9,1)) from rdb$database–result: 123.5 
select cast(123.42 as numeric (9,1)) from rdb$database–result: 123.4
www.firebase.com.br 33 © 2014 – Carlos H. Cantu 
FIM 
Questions? 
www.firebase.com.br 
www.firebirdnews.org 
ThankstoallConferencesponsors:

More Related Content

What's hot

ppt on Segmentation in operationg system
ppt on Segmentation in operationg systemppt on Segmentation in operationg system
ppt on Segmentation in operationg systemsuraj sharma
 
Steganography and Its Applications in Security
Steganography and Its Applications in SecuritySteganography and Its Applications in Security
Steganography and Its Applications in Security
IJMER
 
Case Study On Domain Name Dispute
Case Study On Domain Name DisputeCase Study On Domain Name Dispute
Case Study On Domain Name Dispute
ONKARSINGH
 
Network security cryptographic hash function
Network security  cryptographic hash functionNetwork security  cryptographic hash function
Network security cryptographic hash function
Mijanur Rahman Milon
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
Jan Rüegg
 
Router forensics
Router forensicsRouter forensics
Router forensics
Taruna Chauhan
 
MD-5 : Algorithm
MD-5 : AlgorithmMD-5 : Algorithm
MD-5 : Algorithm
Sahil Kureel
 
Registry forensics
Registry forensicsRegistry forensics
Registry forensics
Prince Boonlia
 
Difference between Cyber and digital Forensic.pptx
Difference between Cyber and digital Forensic.pptxDifference between Cyber and digital Forensic.pptx
Difference between Cyber and digital Forensic.pptx
Applied Forensic Research Sciences
 
CS6701 CRYPTOGRAPHY AND NETWORK SECURITY
CS6701 CRYPTOGRAPHY AND NETWORK SECURITYCS6701 CRYPTOGRAPHY AND NETWORK SECURITY
CS6701 CRYPTOGRAPHY AND NETWORK SECURITY
Kathirvel Ayyaswamy
 
Data Encryption Standard (DES)
Data Encryption Standard (DES)Data Encryption Standard (DES)
Data Encryption Standard (DES)
Haris Ahmed
 
Computer science
Computer scienceComputer science
Computer science
DIGDARSHAN KUNWAR
 
Cyber Crime Types & Tips
Cyber Crime Types & TipsCyber Crime Types & Tips
Cyber Crime Types & Tips
Deepak Kumar (D3)
 
Cryptography - Block cipher & stream cipher
Cryptography - Block cipher & stream cipherCryptography - Block cipher & stream cipher
Cryptography - Block cipher & stream cipher
Niloy Biswas
 
block ciphers
block ciphersblock ciphers
block ciphers
Asad Ali
 
Information and network security 13 playfair cipher
Information and network security 13 playfair cipherInformation and network security 13 playfair cipher
Information and network security 13 playfair cipher
Vaibhav Khanna
 
Memory forensics
Memory forensicsMemory forensics
Memory forensicsSunil Kumar
 
Cryptographic algorithms
Cryptographic algorithmsCryptographic algorithms
Cryptographic algorithms
Anamika Singh
 
Hash function
Hash function Hash function
Hash function
Salman Memon
 
Cryptography & Steganography
Cryptography & SteganographyCryptography & Steganography
Cryptography & Steganography
Animesh Shaw
 

What's hot (20)

ppt on Segmentation in operationg system
ppt on Segmentation in operationg systemppt on Segmentation in operationg system
ppt on Segmentation in operationg system
 
Steganography and Its Applications in Security
Steganography and Its Applications in SecuritySteganography and Its Applications in Security
Steganography and Its Applications in Security
 
Case Study On Domain Name Dispute
Case Study On Domain Name DisputeCase Study On Domain Name Dispute
Case Study On Domain Name Dispute
 
Network security cryptographic hash function
Network security  cryptographic hash functionNetwork security  cryptographic hash function
Network security cryptographic hash function
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
 
Router forensics
Router forensicsRouter forensics
Router forensics
 
MD-5 : Algorithm
MD-5 : AlgorithmMD-5 : Algorithm
MD-5 : Algorithm
 
Registry forensics
Registry forensicsRegistry forensics
Registry forensics
 
Difference between Cyber and digital Forensic.pptx
Difference between Cyber and digital Forensic.pptxDifference between Cyber and digital Forensic.pptx
Difference between Cyber and digital Forensic.pptx
 
CS6701 CRYPTOGRAPHY AND NETWORK SECURITY
CS6701 CRYPTOGRAPHY AND NETWORK SECURITYCS6701 CRYPTOGRAPHY AND NETWORK SECURITY
CS6701 CRYPTOGRAPHY AND NETWORK SECURITY
 
Data Encryption Standard (DES)
Data Encryption Standard (DES)Data Encryption Standard (DES)
Data Encryption Standard (DES)
 
Computer science
Computer scienceComputer science
Computer science
 
Cyber Crime Types & Tips
Cyber Crime Types & TipsCyber Crime Types & Tips
Cyber Crime Types & Tips
 
Cryptography - Block cipher & stream cipher
Cryptography - Block cipher & stream cipherCryptography - Block cipher & stream cipher
Cryptography - Block cipher & stream cipher
 
block ciphers
block ciphersblock ciphers
block ciphers
 
Information and network security 13 playfair cipher
Information and network security 13 playfair cipherInformation and network security 13 playfair cipher
Information and network security 13 playfair cipher
 
Memory forensics
Memory forensicsMemory forensics
Memory forensics
 
Cryptographic algorithms
Cryptographic algorithmsCryptographic algorithms
Cryptographic algorithms
 
Hash function
Hash function Hash function
Hash function
 
Cryptography & Steganography
Cryptography & SteganographyCryptography & Steganography
Cryptography & Steganography
 

Similar to Understanding Numbers in Firebird SQL

Data Analytics and Simulation in Parallel with MATLAB*
Data Analytics and Simulation in Parallel with MATLAB*Data Analytics and Simulation in Parallel with MATLAB*
Data Analytics and Simulation in Parallel with MATLAB*
Intel® Software
 
Big data skew
Big data skewBig data skew
Big data skew
ayan ray
 
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
Dave Stokes
 
U3_4_PointerArithmetic.pdf people will use the above preaentationa dn
U3_4_PointerArithmetic.pdf people will use the above preaentationa dnU3_4_PointerArithmetic.pdf people will use the above preaentationa dn
U3_4_PointerArithmetic.pdf people will use the above preaentationa dn
mit23cs
 
Cassandra Summit 2014: The Cassandra Experience at Orange — Season 2
Cassandra Summit 2014: The Cassandra Experience at Orange — Season 2Cassandra Summit 2014: The Cassandra Experience at Orange — Season 2
Cassandra Summit 2014: The Cassandra Experience at Orange — Season 2
DataStax Academy
 
Introduction to Parallelization and performance optimization
Introduction to Parallelization and performance optimizationIntroduction to Parallelization and performance optimization
Introduction to Parallelization and performance optimization
CSUC - Consorci de Serveis Universitaris de Catalunya
 
COM1407: Variables and Data Types
COM1407: Variables and Data Types COM1407: Variables and Data Types
COM1407: Variables and Data Types
Hemantha Kulathilake
 
Float Data Type in C.pdf
Float Data Type in C.pdfFloat Data Type in C.pdf
Float Data Type in C.pdf
SudhanshiBakre1
 
ScaleGraph - A High-Performance Library for Billion-Scale Graph Analytics
ScaleGraph - A High-Performance Library for Billion-Scale Graph AnalyticsScaleGraph - A High-Performance Library for Billion-Scale Graph Analytics
ScaleGraph - A High-Performance Library for Billion-Scale Graph Analytics
Toyotaro Suzumura
 
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
Fwdays
 
Sheet11-Which of the following is a nonrenewable resourceaSolar e.docx
Sheet11-Which of the following is a nonrenewable resourceaSolar e.docxSheet11-Which of the following is a nonrenewable resourceaSolar e.docx
Sheet11-Which of the following is a nonrenewable resourceaSolar e.docx
bagotjesusa
 
QuadIron An open source library for number theoretic transform-based erasure ...
QuadIron An open source library for number theoretic transform-based erasure ...QuadIron An open source library for number theoretic transform-based erasure ...
QuadIron An open source library for number theoretic transform-based erasure ...
Scality
 
Creating logs for data auditing in FirebirdSQL
Creating logs for data auditing in FirebirdSQLCreating logs for data auditing in FirebirdSQL
Creating logs for data auditing in FirebirdSQL
Mind The Firebird
 
Aerospike Go Language Client
Aerospike Go Language ClientAerospike Go Language Client
Aerospike Go Language Client
Sayyaparaju Sunil
 
High Performance Solr and JVM Tuning Strategies used for MapQuest’s Search Ah...
High Performance Solr and JVM Tuning Strategies used for MapQuest’s Search Ah...High Performance Solr and JVM Tuning Strategies used for MapQuest’s Search Ah...
High Performance Solr and JVM Tuning Strategies used for MapQuest’s Search Ah...
Lucidworks
 
Virtual training optimizing the tick stack
Virtual training  optimizing the tick stackVirtual training  optimizing the tick stack
Virtual training optimizing the tick stack
InfluxData
 
MongoDB Days UK: Tales from the Field
MongoDB Days UK: Tales from the FieldMongoDB Days UK: Tales from the Field
MongoDB Days UK: Tales from the Field
MongoDB
 
OPTIMIZING THE TICK STACK
OPTIMIZING THE TICK STACKOPTIMIZING THE TICK STACK
OPTIMIZING THE TICK STACK
InfluxData
 
Benchmarking Apache Druid
Benchmarking Apache DruidBenchmarking Apache Druid
Benchmarking Apache Druid
Imply
 
Benchmarking Apache Druid
Benchmarking Apache Druid Benchmarking Apache Druid
Benchmarking Apache Druid
Matt Sarrel
 

Similar to Understanding Numbers in Firebird SQL (20)

Data Analytics and Simulation in Parallel with MATLAB*
Data Analytics and Simulation in Parallel with MATLAB*Data Analytics and Simulation in Parallel with MATLAB*
Data Analytics and Simulation in Parallel with MATLAB*
 
Big data skew
Big data skewBig data skew
Big data skew
 
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
 
U3_4_PointerArithmetic.pdf people will use the above preaentationa dn
U3_4_PointerArithmetic.pdf people will use the above preaentationa dnU3_4_PointerArithmetic.pdf people will use the above preaentationa dn
U3_4_PointerArithmetic.pdf people will use the above preaentationa dn
 
Cassandra Summit 2014: The Cassandra Experience at Orange — Season 2
Cassandra Summit 2014: The Cassandra Experience at Orange — Season 2Cassandra Summit 2014: The Cassandra Experience at Orange — Season 2
Cassandra Summit 2014: The Cassandra Experience at Orange — Season 2
 
Introduction to Parallelization and performance optimization
Introduction to Parallelization and performance optimizationIntroduction to Parallelization and performance optimization
Introduction to Parallelization and performance optimization
 
COM1407: Variables and Data Types
COM1407: Variables and Data Types COM1407: Variables and Data Types
COM1407: Variables and Data Types
 
Float Data Type in C.pdf
Float Data Type in C.pdfFloat Data Type in C.pdf
Float Data Type in C.pdf
 
ScaleGraph - A High-Performance Library for Billion-Scale Graph Analytics
ScaleGraph - A High-Performance Library for Billion-Scale Graph AnalyticsScaleGraph - A High-Performance Library for Billion-Scale Graph Analytics
ScaleGraph - A High-Performance Library for Billion-Scale Graph Analytics
 
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
 
Sheet11-Which of the following is a nonrenewable resourceaSolar e.docx
Sheet11-Which of the following is a nonrenewable resourceaSolar e.docxSheet11-Which of the following is a nonrenewable resourceaSolar e.docx
Sheet11-Which of the following is a nonrenewable resourceaSolar e.docx
 
QuadIron An open source library for number theoretic transform-based erasure ...
QuadIron An open source library for number theoretic transform-based erasure ...QuadIron An open source library for number theoretic transform-based erasure ...
QuadIron An open source library for number theoretic transform-based erasure ...
 
Creating logs for data auditing in FirebirdSQL
Creating logs for data auditing in FirebirdSQLCreating logs for data auditing in FirebirdSQL
Creating logs for data auditing in FirebirdSQL
 
Aerospike Go Language Client
Aerospike Go Language ClientAerospike Go Language Client
Aerospike Go Language Client
 
High Performance Solr and JVM Tuning Strategies used for MapQuest’s Search Ah...
High Performance Solr and JVM Tuning Strategies used for MapQuest’s Search Ah...High Performance Solr and JVM Tuning Strategies used for MapQuest’s Search Ah...
High Performance Solr and JVM Tuning Strategies used for MapQuest’s Search Ah...
 
Virtual training optimizing the tick stack
Virtual training  optimizing the tick stackVirtual training  optimizing the tick stack
Virtual training optimizing the tick stack
 
MongoDB Days UK: Tales from the Field
MongoDB Days UK: Tales from the FieldMongoDB Days UK: Tales from the Field
MongoDB Days UK: Tales from the Field
 
OPTIMIZING THE TICK STACK
OPTIMIZING THE TICK STACKOPTIMIZING THE TICK STACK
OPTIMIZING THE TICK STACK
 
Benchmarking Apache Druid
Benchmarking Apache DruidBenchmarking Apache Druid
Benchmarking Apache Druid
 
Benchmarking Apache Druid
Benchmarking Apache Druid Benchmarking Apache Druid
Benchmarking Apache Druid
 

More from Mind The Firebird

Tips for using Firebird system tables
Tips for using Firebird system tablesTips for using Firebird system tables
Tips for using Firebird system tablesMind The Firebird
 
Using Azure cloud and Firebird to develop applications easily
Using Azure cloud and Firebird to develop applications easilyUsing Azure cloud and Firebird to develop applications easily
Using Azure cloud and Firebird to develop applications easily
Mind The Firebird
 
A year in the life of Firebird .Net provider
A year in the life of Firebird .Net providerA year in the life of Firebird .Net provider
A year in the life of Firebird .Net providerMind The Firebird
 
How Firebird transactions work
How Firebird transactions workHow Firebird transactions work
How Firebird transactions workMind The Firebird
 
SuperServer in Firebird 3
SuperServer in Firebird 3SuperServer in Firebird 3
SuperServer in Firebird 3
Mind The Firebird
 
Using ТРСС to study Firebird performance
Using ТРСС to study Firebird performanceUsing ТРСС to study Firebird performance
Using ТРСС to study Firebird performance
Mind The Firebird
 
Overview of RedDatabase 2.5
Overview of RedDatabase 2.5Overview of RedDatabase 2.5
Overview of RedDatabase 2.5
Mind The Firebird
 
Firebird Performance counters in details
Firebird Performance counters in detailsFirebird Performance counters in details
Firebird Performance counters in details
Mind The Firebird
 
Threading through InterBase, Firebird, and beyond
Threading through InterBase, Firebird, and beyondThreading through InterBase, Firebird, and beyond
Threading through InterBase, Firebird, and beyond
Mind The Firebird
 
New SQL Features in Firebird 3, by Vlad Khorsun
New SQL Features in Firebird 3, by Vlad KhorsunNew SQL Features in Firebird 3, by Vlad Khorsun
New SQL Features in Firebird 3, by Vlad Khorsun
Mind The Firebird
 
Orphans, Corruption, Careful Write, and Logging
Orphans, Corruption, Careful Write, and LoggingOrphans, Corruption, Careful Write, and Logging
Orphans, Corruption, Careful Write, and Logging
Mind The Firebird
 
Firebird release strategy and roadmap for 2015/2016
Firebird release strategy and roadmap for 2015/2016Firebird release strategy and roadmap for 2015/2016
Firebird release strategy and roadmap for 2015/2016
Mind The Firebird
 
Nbackup and Backup: Internals, Usage strategy and Pitfalls, by Dmitry Kuzmenk...
Nbackup and Backup: Internals, Usage strategy and Pitfalls, by Dmitry Kuzmenk...Nbackup and Backup: Internals, Usage strategy and Pitfalls, by Dmitry Kuzmenk...
Nbackup and Backup: Internals, Usage strategy and Pitfalls, by Dmitry Kuzmenk...
Mind The Firebird
 
Working with Large Firebird databases
Working with Large Firebird databasesWorking with Large Firebird databases
Working with Large Firebird databases
Mind The Firebird
 
Stored procedures in Firebird
Stored procedures in FirebirdStored procedures in Firebird
Stored procedures in Firebird
Mind The Firebird
 
Superchaging big production systems on Firebird: transactions, garbage, maint...
Superchaging big production systems on Firebird: transactions, garbage, maint...Superchaging big production systems on Firebird: transactions, garbage, maint...
Superchaging big production systems on Firebird: transactions, garbage, maint...
Mind The Firebird
 
Firebird meets NoSQL
Firebird meets NoSQLFirebird meets NoSQL
Firebird meets NoSQL
Mind The Firebird
 
Continuous Database Monitoring with the Trace API
Continuous Database Monitoring with the Trace APIContinuous Database Monitoring with the Trace API
Continuous Database Monitoring with the Trace API
Mind The Firebird
 

More from Mind The Firebird (20)

Tips for using Firebird system tables
Tips for using Firebird system tablesTips for using Firebird system tables
Tips for using Firebird system tables
 
Using Azure cloud and Firebird to develop applications easily
Using Azure cloud and Firebird to develop applications easilyUsing Azure cloud and Firebird to develop applications easily
Using Azure cloud and Firebird to develop applications easily
 
A year in the life of Firebird .Net provider
A year in the life of Firebird .Net providerA year in the life of Firebird .Net provider
A year in the life of Firebird .Net provider
 
How Firebird transactions work
How Firebird transactions workHow Firebird transactions work
How Firebird transactions work
 
SuperServer in Firebird 3
SuperServer in Firebird 3SuperServer in Firebird 3
SuperServer in Firebird 3
 
Copycat presentation
Copycat presentationCopycat presentation
Copycat presentation
 
Using ТРСС to study Firebird performance
Using ТРСС to study Firebird performanceUsing ТРСС to study Firebird performance
Using ТРСС to study Firebird performance
 
Overview of RedDatabase 2.5
Overview of RedDatabase 2.5Overview of RedDatabase 2.5
Overview of RedDatabase 2.5
 
Firebird Performance counters in details
Firebird Performance counters in detailsFirebird Performance counters in details
Firebird Performance counters in details
 
Threading through InterBase, Firebird, and beyond
Threading through InterBase, Firebird, and beyondThreading through InterBase, Firebird, and beyond
Threading through InterBase, Firebird, and beyond
 
New SQL Features in Firebird 3, by Vlad Khorsun
New SQL Features in Firebird 3, by Vlad KhorsunNew SQL Features in Firebird 3, by Vlad Khorsun
New SQL Features in Firebird 3, by Vlad Khorsun
 
Orphans, Corruption, Careful Write, and Logging
Orphans, Corruption, Careful Write, and LoggingOrphans, Corruption, Careful Write, and Logging
Orphans, Corruption, Careful Write, and Logging
 
Firebird release strategy and roadmap for 2015/2016
Firebird release strategy and roadmap for 2015/2016Firebird release strategy and roadmap for 2015/2016
Firebird release strategy and roadmap for 2015/2016
 
Nbackup and Backup: Internals, Usage strategy and Pitfalls, by Dmitry Kuzmenk...
Nbackup and Backup: Internals, Usage strategy and Pitfalls, by Dmitry Kuzmenk...Nbackup and Backup: Internals, Usage strategy and Pitfalls, by Dmitry Kuzmenk...
Nbackup and Backup: Internals, Usage strategy and Pitfalls, by Dmitry Kuzmenk...
 
Working with Large Firebird databases
Working with Large Firebird databasesWorking with Large Firebird databases
Working with Large Firebird databases
 
Stored procedures in Firebird
Stored procedures in FirebirdStored procedures in Firebird
Stored procedures in Firebird
 
Firebird on Linux
Firebird on LinuxFirebird on Linux
Firebird on Linux
 
Superchaging big production systems on Firebird: transactions, garbage, maint...
Superchaging big production systems on Firebird: transactions, garbage, maint...Superchaging big production systems on Firebird: transactions, garbage, maint...
Superchaging big production systems on Firebird: transactions, garbage, maint...
 
Firebird meets NoSQL
Firebird meets NoSQLFirebird meets NoSQL
Firebird meets NoSQL
 
Continuous Database Monitoring with the Trace API
Continuous Database Monitoring with the Trace APIContinuous Database Monitoring with the Trace API
Continuous Database Monitoring with the Trace API
 

Recently uploaded

Game Development with Unity3D (Game Development lecture 3)
Game Development  with Unity3D (Game Development lecture 3)Game Development  with Unity3D (Game Development lecture 3)
Game Development with Unity3D (Game Development lecture 3)
abdulrafaychaudhry
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
abdulrafaychaudhry
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
ShamsuddeenMuhammadA
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
abdulrafaychaudhry
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 

Recently uploaded (20)

Game Development with Unity3D (Game Development lecture 3)
Game Development  with Unity3D (Game Development lecture 3)Game Development  with Unity3D (Game Development lecture 3)
Game Development with Unity3D (Game Development lecture 3)
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 

Understanding Numbers in Firebird SQL

  • 1. www.firebase.com.br 1 © 2014 – Carlos H. Cantu Understanding Numbers in Firebird Carlos H. Cantuwww.firebase.com.br www.firebirdnews.org
  • 2. www.firebase.com.br 2 © 2014 – Carlos H. Cantu Who am I? • Maintainer of www.firebase.com.br and www.firebirdnews.org • Author of 2 Firebird books published in Brazil • Software developer for about 30 years • Organizer of the Firebird Developers Day conference • Firebird consultant
  • 3. www.firebase.com.br 3 © 2014 – Carlos H. Cantu Do you wannago crazy?!
  • 4. www.firebase.com.br 4 © 2014 – Carlos H. Cantu Warnings! 1. Internal storage type depends on database dialect 2. The dialect has influence in the precision of some types and in the results of calculations 3. Depending on the datatypeused, the retrieved value can be different from the original value!! 4. Decimal separator is always the dot “.”
  • 5. www.firebase.com.br 5 © 2014 – Carlos H. Cantu INTEGER types • SMALLINT – 16 bits – between -32.768 and32.767 • INTEGER – 32 bits – between -2.147.483.648 and 2.147.483.647 • BIGINT – 64 bits – between -9.223.372.036.854.775.808 and 9.223.372.036.854.775.807 – Only available in dialect 3
  • 6. www.firebase.com.br 6 © 2014 – Carlos H. Cantu FLOATING POINT types • FLOAT – 32 bits: 1 for signal, 8 for exponent and 23 for the mantissa. – 7 digits of precision – Between -3.4 x 1038and 3.4 x 1038 • DOUBLE PRECISION – 64 bits: 1 for signal, 11 for exponent and 52 for the mantissa. – 15 digits of precision – Between -1.7 x 10308and 1.7 x 10308
  • 7. www.firebase.com.br 7 © 2014 – Carlos H. Cantu Pros and cons of floating types • Stored following the standard defined by the IEEE (Institute of Electrical and Electronics Engineers), with an approximated representation of the real number. • Calculations uses the math co-processor (faster). • Not recommended due to lack of precision.
  • 8. www.firebase.com.br 8 © 2014 – Carlos H. Cantu Accuracy in FLOAT/DOUBLE (1/2) SQL> select cast(1234567.1234 as float) from rdb$database; CAST ============== 1234567.1 Result displayed by IBExpert: 1234567.125
  • 9. www.firebase.com.br 9 © 2014 – Carlos H. Cantu Imprecision in FLOAT/DOUBLE (2/2) SQL> select cast(1234567.4321 as float) from rdb$database; CAST ============== 1234567.4 Result displayed by IBExpert: 1234567.375
  • 10. www.firebase.com.br 10 © 2014 – Carlos H. Cantu Fixed point • NUMERIC (p,s) / DECIMAL (p,s) • Is stored occupying either 16, 32 or 64 bits • p= precision (total digits) [1 <= p <= 18] s= scale (number of digits after the “comma”) • smust be always lower or equal to p • If pand sis not informed, the internal type will be INTEGER • In FB, palways determinates the minimum number of stored digits (not follow the standard) • The retrieved value is always exactly equal to the original value!
  • 11. www.firebase.com.br 11 © 2014 – Carlos H. Cantu Internal storage of NUMERIC and DECIMAL PRECISION INTERNAL TYPE DIALECT 3 DIALECT 1 1..4 NUMERIC SMALLINT (*) SMALLINT 1..4 DECIMAL INTEGER (*) INTEGER 5..9 NUMERIC e DECIMAL INTEGER INTEGER 10..18 NUMERIC e DECIMAL BIGINT DOUBLE PRECISION(!) In Firebird, DECIMAL andNUMERICsare thesamething, ifp < 10. (*) In this case, the range of supported values are different compared to NUMERIC and DECIMAL
  • 12. www.firebase.com.br 12 © 2014 – Carlos H. Cantu Determining the capacity of chosen numeric/decimals 1. Check the internal type used depending on the precision (p) of the field. 2. Check the range of values supported by the internal type. 3. Divide the min and max values by 10s to know the effective range of accepted values for the field.
  • 13. www.firebase.com.br 13 © 2014 – Carlos H. Cantu Determining the capacity of chosen numeric/decimals Example: 1. NUMERIC (9,2) or DECIMAL (9,2) 2. Internally stored as INTEGER 3. Integer = -2.147.483.648 to 2.147.483.647 4. As s = 2, divide by 102 5. Accepted range for a field declared as NUMERIC/DECIMAL (9,2) = -21.474.836,48 to 21.474.836,47
  • 14. www.firebase.com.br 14 © 2014 – Carlos H. Cantu Testing the limits of numeric/decimal SQL> select cast(-21474836.48 as numeric (9,2)), cast(-21474836.48 as decimal (9,2)) from rdb$database; CAST CAST ============ ============ -21474836.48 -21474836.48 SQL> select cast(-21474836.49as numeric (9,2)), cast(-21474836.49as decimal (9,2)) from rdb$database; CAST CAST ============ ============ Statement failed, SQLSTATE = 22003 arithmetic exception, numeric overflow, or string truncation -numeric value is out of range
  • 15. www.firebase.com.br 15 © 2014 – Carlos H. Cantu Testing the limits of numeric/decimal SQL> select cast(32768 as decimal(4,0)) from rdb$database; --integer CAST ============ 32768 SQL> select cast(32768 as numeric(4,0)) from rdb$database; --smallint CAST ======= Statement failed, SQLSTATE = 22003 arithmetic exception, numeric overflow, or string truncation -numeric value is out of range
  • 16. www.firebase.com.br 16 © 2014 – Carlos H. Cantu Moving from dialect 1 to 3 • Is there any field declared as NUMERIC or DECIMALwith p > 9? – No: there will be no problem at all – Yes: you may have problems! • NUMERIC and DECIMAL with p > 9 are stored as double precision in dialect 1 and the existing fields will stay like this if the DB is “migrated” to dialect 3 using gfix-sql_dialect3. • New fields declared as NUM/DEC with p > 9, created after the DB was converted to dialect 3 will use BIGINTinternally. • Recommended solution: create a new DB using a script and pump the data from old to new database.
  • 17. www.firebase.com.br 17 © 2014 – Carlos H. Cantu Integer divisions • Dialect 1, dividing intby intresults in double precisionI.e.: 1/3 = 0,3333333333333 • Dialect 3, divide intby intresults in integerI.e.: 1/3 = 0
  • 18. www.firebase.com.br 18 © 2014 – Carlos H. Cantu Division/Multiplication of fixed point numerics • In dialect 1, the division will always return a double precision. • In dialect 3, the result will be a type withp= 18 and s= sum of the scales of the involved types. SQL> select cast(0.33 as numeric (9,2))/ cast (1 as numeric(9,2)) from rdb$database; DIVIDE ===================== 0.3300
  • 19. www.firebase.com.br 19 © 2014 – Carlos H. Cantu Division/Multiplication of fixed point numerics SQL> select (3.00/1.00*3.5)*2.00as totalfrom rdb$database; TOTAL ===================== 21.0000000 SQL> select (3.00/1.00/3.5)/2.00as totalfrom rdb$database; TOTAL ===================== 0.4285700
  • 20. www.firebase.com.br 20 © 2014 – Carlos H. Cantu Division/Multiplication of fixed point numerics • There can be overflows, specially with calculations involving multiple arguments! select cast(1 as numeric(15,6))* cast(1 as numeric(9,8)) * cast(1 as numeric(15,5)) from rdb$database ~ 1.000000* 1.00000000* 1.00000 Integer overflow. The result of an integer operation caused the most significant bit of the result to carry.
  • 21. www.firebase.com.br 21 © 2014 – Carlos H. Cantu Addition/Subtraction of fixed point numbers • Result will have sequal the biggest scale of the bigger member of the operation. • In dialect 1, result will always have p= 9 • In dialect 3, result will always have p= 18 SQL> select cast(1 as numeric(9,2)) + cast(2 as integer) from rdb$database; ADD ===================== 3.00 SQL> select cast(0.5 as numeric(9,2)) – cast(1 as numeric(9,3)) from rdb$database; SUBTRACT ===================== -0.500
  • 22. www.firebase.com.br 22 © 2014 – Carlos H. Cantu Tips summary • Always create the database in dialect 3, and connect to it using the same dialect. • For “monetary” fields, choose numericor decimalto guarantee the accuracy. • When need to store numbers with variable scale (s), choose double precision. • To migrate a DB from dialect 1 to 3, prefers to PUMP the data instead of using gfix. • Take care with overflows in calculations involving numeric/decimal.
  • 23. www.firebase.com.br 23 © 2014 – Carlos H. Cantu Curiosities INDEXES • Numbers are stored in keys as double precision (exception to the rule is BIGINT) • Pros: – For numeric/decimal, allows changing p or s without needing to reindex – For smallint/integer, allows converting between the types or to a type having a scale (s) without need to reindex • Obs: Due to lack of precision of the double precision, the search if done in an interval between the bigger previous value and the lower next value related to the searched value. GENERATORS • Dialect 1 = integer • Dialect 3 = bigint
  • 24. www.firebase.com.br 24 © 2014 – Carlos H. Cantu Curiosities (do you wannago more crazy??) CHECK CONSTRAINTS and CLIENT DIALECTS The rules applied by a check constraint are based on the dialect used by the client connection in the time the constraint was created. Ex: check (int1 / int2) > 0.5 (rule created with dialect 1 connection) When connecting to the DB using dialect 3: Insert ... (int1, int2) values (2, 3); --Success! ~ 0.66666666 Ex: check (int1 / int2) > 0.5 (rule created with dialect 3 connection) Insert ... (int1, int2) values (2, 3); --FAILURE! ~ 0
  • 25. www.firebase.com.br 25 © 2014 – Carlos H. Cantu Changing the scale of numeric/decimal fields • Raising the scale means shortening the range of accepted values I.e.: numeric (9,2): range -21.474.836,48 to21.474.836,47 numeric (9,3): range -2.147.483,648 to2.147.483,647 This operation is not defined for system tables. Unsuccessful metadata update. New scale specified for column AFIELD must be at most 2.
  • 26. www.firebase.com.br 26 © 2014 – Carlos H. Cantu Changing the scale of numeric/decimal fields • Changing the scale of (9,2) to 3. • Solutions: – Create new field declared as (9,3) – Copy the values to the new field – Drop the old field – Rename the new field as the old one • Changing to (10,3) – Problem if there are indexes defined for that field, since the internal type changes to bigint!
  • 27. www.firebase.com.br 27 © 2014 – Carlos H. Cantu Changing the scale of numeric/decimal fields create table test (afield numeric (9,2)); commit; insert into test values (10.12); commit; alter table test alter afield type numeric (9,3); This operation is not defined for system tables. Unsuccessful metadata update. New scale specified for column AFIELD must be at most 2. alter table test alter afield type numeric (10,3); commit; update test set afield = 10.123; commit; select afield from test; commit; Result:10.123
  • 28. www.firebase.com.br 28 © 2014 – Carlos H. Cantu Changing the scale of numeric/decimal fields alter table test alter afieldtype numeric (10,2); commit; select afield from test; commit; Result:10.12 alter table test alter afield type numeric (11,3); commit; select afield from test; commit; Result:10.123
  • 29. www.firebase.com.br 29 © 2014 – Carlos H. Cantu Changing the scale of numeric/decimal fields alter table test alter afield type numeric (10,2); commit; select afield from test; commit; Result:10.12 /* “Dumb” Update */ update test set afield = afield; commit; alter table test alter afield type numeric (11,3); commit; select afield from test; commit; Result:10.120
  • 30. www.firebase.com.br 30 © 2014 – Carlos H. Cantu Changing the scale of numeric/decimal fields “Hardcore” solution: update RDB$FIELDS setRDB$FIELD_SCALE = -3where RDB$FIELD_NAME = 'RDB$nnn'; Warning! • Be sure that the existing values “fits” in the new range, otherwise some records will be inaccessible(corruption). • Will not work in Firebird 3!
  • 31. www.firebase.com.br 31 © 2014 – Carlos H. Cantu Additional attention! • When changing the “size” of an existing field, it can be identified with a different type by the “language/access technology” used in the client application.
  • 32. www.firebase.com.br 32 © 2014 – Carlos H. Cantu Roudings • Firebird uses “standard rounding”: -Chose what digit will be the limit-Add 1 if the next digit is >= 5-Don’t change the digit if the next is < 5 I.e.: select cast(123.45 as numeric (9,1)) from rdb$database–result: 123.5 select cast(123.42 as numeric (9,1)) from rdb$database–result: 123.4
  • 33. www.firebase.com.br 33 © 2014 – Carlos H. Cantu FIM Questions? www.firebase.com.br www.firebirdnews.org ThankstoallConferencesponsors: