john
john

Reputation: 2544

BigQuery: How to represent integer of type Long in Bigquery?

I have a dataset that contains integer of type “Long”. I need to analyse that dataset by doing some arithmetic operations on it. What are the possible ways to do that?

I have tried casting to FLOAT but then I can't use some operations like bitwise AND etc on that data type.

As an example, here is the value of one field

18446744073709551615

Thanks

Upvotes: 4

Views: 5650

Answers (2)

Nimit Nagpal
Nimit Nagpal

Reputation: 31

The long range for integer is :

The long data type is a 64-bit two's complement integer. The signed long has a minimum value of -2^63 and a maximum value of 2^63-1

In BigQuery normal Integer long is represented by INT64(INTEGER).

Google Big-Query documentation : https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#integer_type.

** Basically, long maps to INTEGER (INT64) which has a larger range in bigquery. **

So, if you keep it as INTEGER type, and the arithmethic operation doesn't result in decimal points to the final value, you should be okay in representing with data type INTEGER in BigQuery.

Upvotes: 3

Gordon Linoff
Gordon Linoff

Reputation: 1270411

You can use numeric if you want to keep a number and all its decimal points:

select cast('18446744073709551615' as numeric)

This is not infinitely flexible. It is actually equivalent to numeric(38, 9) in any other database. BigQuery offers no control over the scale and precision. This is described in the documentation (admittedly, this is a very recent addition to BigQuery).

Upvotes: 4

Related Questions