Reputation: 59175
Chrome V8 - the JavaScript engine - recently added support for BigInt - arbitrary precision large integers:
Can I use these BigInt in BigQuery?
Upvotes: 0
Views: 572
Reputation: 59175
Yes! BigQuery runs one of the latest versions of V8, so it already supports BigInts.
To use them:
CREATE TEMP FUNCTION testBigInt()
RETURNS ARRAY<STRING>
LANGUAGE js AS """
return [
Number.MAX_SAFE_INTEGER
, Number.MAX_SAFE_INTEGER+2
, Number.MAX_SAFE_INTEGER+1
, Number.MAX_SAFE_INTEGER+100
, BigInt(Number.MAX_SAFE_INTEGER) + 2n];
""";
SELECT testBigInt()
9007199254740991
9007199254740992
9007199254740992
9007199254741092
9007199254740993
From the results, note that JavaScript silently produces the wrong answer when not using BigInt - hence the need for BigInts.
To keep the BigInts compatible with BigQuery, you'll need to treat them as String. Stay tuned, as we've requested improvements for this.
With the wrong types you might get these errors:
Upvotes: 3