tsql icon indicating copy to clipboard operation
tsql copied to clipboard

Document differences in CAST(... AS BIGINT)

Open AnyhowStep opened this issue 5 years ago • 1 comments
trafficstars

SELECT 
  CAST(1.1 AS BIGINT),
  CAST(1.5 AS BIGINT),
  CAST(1.7 AS BIGINT),
  CAST(-1.1 AS BIGINT),
  CAST(-1.5 AS BIGINT),
  CAST(-1.7 AS BIGINT);

PostgreSQL,

int8 int8 int8 int8 int8 int8
1 2 2 -1 -2 -2

SQLite,

CAST(1.1 AS BIGINT) CAST(1.5 AS BIGINT) CAST(1.7 AS BIGINT) CAST(-1.1 AS BIGINT) CAST(-1.5 AS BIGINT) CAST(-1.7 AS BIGINT)
1 1 1 -1 -1 -1

MySQL,

CAST(1.1 AS SIGNED) CAST(1.5 AS SIGNED) CAST(1.7 AS SIGNED) CAST(-1.1 AS SIGNED) CAST(-1.5 AS SIGNED) CAST(-1.7 AS SIGNED)
1 2 2 -1 -2 -2

AnyhowStep avatar Feb 17 '20 20:02 AnyhowStep

SQLite truncates.

MySQL and PostgreSQL round.

AnyhowStep avatar Feb 17 '20 20:02 AnyhowStep