Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 377
john Avatar asked Sep 03 '25 16:09

john


2 Answers

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).

like image 130
Gordon Linoff Avatar answered Sep 05 '25 08:09

Gordon Linoff


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.

like image 41
Nimit Nagpal Avatar answered Sep 05 '25 06:09

Nimit Nagpal