HiveBrain v1.2.0
Get Started
← Back to all entries
gotchasqlModerate

What's the difference between "expression <=1." and "expression <= 1"?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
expressionthewhatdifferencebetweenand

Problem

Reviewing code and a case statement has expression <= 1. as opposed to <= 1

I'm not sure what the purpose of the 1. is. Any thoughts?

Solution

1. is a NUMERIC (or DECIMAL) constant, while 1 is an INTEGER constant. In some cases it is useful to specify the data type of a constant explicitly to avoid an unnecessary (or undesirable) implicit type conversion.

Consider, for example

create table t(f1 int);
insert into t values (2);


Then select 1/f1 from t returns 0 (INTEGER), while select 1./f1 from t returns 0.5 (DECIMAL).

One might assume that on the left side of the comparison in your example there is a DECIMAL column, and explicitly specifying a DECIMAL constant could marginally improve performance by avoiding an implicit type cast.

Code Snippets

create table t(f1 int);
insert into t values (2);

Context

StackExchange Database Administrators Q#105616, answer score: 18

Revisions (0)

No revisions yet.