简体   繁体   中英

From Snowflake query to python dataframe problem in data type mapping

I have a problem casting data type from a snowflake query into pandas dataframe. I want to use the smaller data types as possible in order to reduce my memory usage. Thus, I would like to have my pandas columns into int8 or int16 for integer, instead of the int64 that i have for the moment.

My problem is the following:

From the snowflake documentation, we can read that: from a snowflake number we can cast in any integer type in python

I tried to cast my int columns in the following manner:

select myvariable::smallint
from mytable 

and

select myvariable::number(5,0) -- totaly arbitrary precision, depends on the column
from mytable 

which are supposed to be smaller data types.

However, any of thoses solutions do not work and i still have int64 types in my pandas dataframe.

I did not see any parameter to add in my snowflake connector, or in the query. I Know I can cast the data type directly in python, but I would like that the transformation is directly made from snowflake.

If anyone know a solution for this, I would be very interested

Snowflake's INTEGER data types are all INT64 actually.

The various names (SMALLINT like in your example) are to simplify porting from other systems and to suggest the expected range of values for a column of the specified type, but they are still INT64.

For more information have a look here .

You will have to cast the data type directly in Python.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM