SlideShare ist ein Scribd-Unternehmen logo
1 von 33
Downloaden Sie, um offline zu lesen
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:

Weitere ähnliche Inhalte

Was ist angesagt?

Relational vs Non Relational Databases
Relational vs Non Relational DatabasesRelational vs Non Relational Databases
Relational vs Non Relational DatabasesAngelica Lo Duca
 
Overview of Data Base Systems Concepts and Architecture
Overview of Data Base Systems Concepts and ArchitectureOverview of Data Base Systems Concepts and Architecture
Overview of Data Base Systems Concepts and ArchitectureRubal Sagwal
 
Scylla Summit 2022: Migrating SQL Schemas for ScyllaDB: Data Modeling Best Pr...
Scylla Summit 2022: Migrating SQL Schemas for ScyllaDB: Data Modeling Best Pr...Scylla Summit 2022: Migrating SQL Schemas for ScyllaDB: Data Modeling Best Pr...
Scylla Summit 2022: Migrating SQL Schemas for ScyllaDB: Data Modeling Best Pr...ScyllaDB
 
Business Intelligence: Multidimensional Analysis
Business Intelligence: Multidimensional AnalysisBusiness Intelligence: Multidimensional Analysis
Business Intelligence: Multidimensional AnalysisMichael Lamont
 
Achieving compliance With MongoDB Security
Achieving compliance With MongoDB Security Achieving compliance With MongoDB Security
Achieving compliance With MongoDB Security Mydbops
 
AWS 9월 웨비나 | Amazon Aurora Deep Dive
AWS 9월 웨비나 | Amazon Aurora Deep DiveAWS 9월 웨비나 | Amazon Aurora Deep Dive
AWS 9월 웨비나 | Amazon Aurora Deep DiveAmazon Web Services Korea
 
CloudStack - Top 5 Technical Issues and Troubleshooting
CloudStack - Top 5 Technical Issues and TroubleshootingCloudStack - Top 5 Technical Issues and Troubleshooting
CloudStack - Top 5 Technical Issues and TroubleshootingShapeBlue
 
introduction to NOSQL Database
introduction to NOSQL Databaseintroduction to NOSQL Database
introduction to NOSQL Databasenehabsairam
 
Row or Columnar Database
Row or Columnar DatabaseRow or Columnar Database
Row or Columnar DatabaseBiju Nair
 
Advance database system(part 8)
Advance database system(part 8)Advance database system(part 8)
Advance database system(part 8)Abdullah Khosa
 
How to Manage Scale-Out Environments with MariaDB MaxScale
How to Manage Scale-Out Environments with MariaDB MaxScaleHow to Manage Scale-Out Environments with MariaDB MaxScale
How to Manage Scale-Out Environments with MariaDB MaxScaleMariaDB plc
 
MariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAsMariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAsFederico Razzoli
 
Appache Cassandra
Appache Cassandra  Appache Cassandra
Appache Cassandra nehabsairam
 
What Every Developer Should Know About Database Scalability
What Every Developer Should Know About Database ScalabilityWhat Every Developer Should Know About Database Scalability
What Every Developer Should Know About Database Scalabilityjbellis
 

Was ist angesagt? (20)

NoSQL databases
NoSQL databasesNoSQL databases
NoSQL databases
 
Index in sql server
Index in sql serverIndex in sql server
Index in sql server
 
Relational vs Non Relational Databases
Relational vs Non Relational DatabasesRelational vs Non Relational Databases
Relational vs Non Relational Databases
 
Overview of Data Base Systems Concepts and Architecture
Overview of Data Base Systems Concepts and ArchitectureOverview of Data Base Systems Concepts and Architecture
Overview of Data Base Systems Concepts and Architecture
 
Scylla Summit 2022: Migrating SQL Schemas for ScyllaDB: Data Modeling Best Pr...
Scylla Summit 2022: Migrating SQL Schemas for ScyllaDB: Data Modeling Best Pr...Scylla Summit 2022: Migrating SQL Schemas for ScyllaDB: Data Modeling Best Pr...
Scylla Summit 2022: Migrating SQL Schemas for ScyllaDB: Data Modeling Best Pr...
 
History of Database
History  of DatabaseHistory  of Database
History of Database
 
Chapter25
Chapter25Chapter25
Chapter25
 
Virtualization basics
Virtualization basics Virtualization basics
Virtualization basics
 
Business Intelligence: Multidimensional Analysis
Business Intelligence: Multidimensional AnalysisBusiness Intelligence: Multidimensional Analysis
Business Intelligence: Multidimensional Analysis
 
Achieving compliance With MongoDB Security
Achieving compliance With MongoDB Security Achieving compliance With MongoDB Security
Achieving compliance With MongoDB Security
 
AWS 9월 웨비나 | Amazon Aurora Deep Dive
AWS 9월 웨비나 | Amazon Aurora Deep DiveAWS 9월 웨비나 | Amazon Aurora Deep Dive
AWS 9월 웨비나 | Amazon Aurora Deep Dive
 
CloudStack - Top 5 Technical Issues and Troubleshooting
CloudStack - Top 5 Technical Issues and TroubleshootingCloudStack - Top 5 Technical Issues and Troubleshooting
CloudStack - Top 5 Technical Issues and Troubleshooting
 
introduction to NOSQL Database
introduction to NOSQL Databaseintroduction to NOSQL Database
introduction to NOSQL Database
 
Row or Columnar Database
Row or Columnar DatabaseRow or Columnar Database
Row or Columnar Database
 
Advance database system(part 8)
Advance database system(part 8)Advance database system(part 8)
Advance database system(part 8)
 
How to Manage Scale-Out Environments with MariaDB MaxScale
How to Manage Scale-Out Environments with MariaDB MaxScaleHow to Manage Scale-Out Environments with MariaDB MaxScale
How to Manage Scale-Out Environments with MariaDB MaxScale
 
MariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAsMariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAs
 
Appache Cassandra
Appache Cassandra  Appache Cassandra
Appache Cassandra
 
What Every Developer Should Know About Database Scalability
What Every Developer Should Know About Database ScalabilityWhat Every Developer Should Know About Database Scalability
What Every Developer Should Know About Database Scalability
 
Sql server basics
Sql server basicsSql server basics
Sql server basics
 

Ähnlich wie 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 skewayan 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 2014Dave 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 dnmit23cs
 
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 2DataStax Academy
 
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.pdfSudhanshiBakre1
 
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 AnalyticsToyotaro 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 TatarynovFwdays
 
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.docxbagotjesusa
 
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 FirebirdSQLMind The Firebird
 
Aerospike Go Language Client
Aerospike Go Language ClientAerospike Go Language Client
Aerospike Go Language ClientSayyaparaju 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 stackInfluxData
 
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 FieldMongoDB
 
OPTIMIZING THE TICK STACK
OPTIMIZING THE TICK STACKOPTIMIZING THE TICK STACK
OPTIMIZING THE TICK STACKInfluxData
 
Benchmarking Apache Druid
Benchmarking Apache DruidBenchmarking Apache Druid
Benchmarking Apache DruidImply
 
Benchmarking Apache Druid
Benchmarking Apache Druid Benchmarking Apache Druid
Benchmarking Apache Druid Matt Sarrel
 

Ähnlich wie 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
 

Mehr von 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 easilyMind 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
 
Using ТРСС to study Firebird performance
Using ТРСС to study Firebird performanceUsing ТРСС to study Firebird performance
Using ТРСС to study Firebird performanceMind The Firebird
 
Firebird Performance counters in details
Firebird Performance counters in detailsFirebird Performance counters in details
Firebird Performance counters in detailsMind The Firebird
 
Threading through InterBase, Firebird, and beyond
Threading through InterBase, Firebird, and beyondThreading through InterBase, Firebird, and beyond
Threading through InterBase, Firebird, and beyondMind 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 KhorsunMind The Firebird
 
Orphans, Corruption, Careful Write, and Logging
Orphans, Corruption, Careful Write, and LoggingOrphans, Corruption, Careful Write, and Logging
Orphans, Corruption, Careful Write, and LoggingMind 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/2016Mind 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 databasesMind The Firebird
 
Stored procedures in Firebird
Stored procedures in FirebirdStored procedures in Firebird
Stored procedures in FirebirdMind 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
 
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 APIMind The Firebird
 

Mehr von 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
 

Kürzlich hochgeladen

%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 

Kürzlich hochgeladen (20)

Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 

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: