How does Snowflake handle NULL values?

无人久伴 提交于 2020-03-05 05:59:28

问题


For example, in my dataframe I have a column of NULL values that I plan to edit later, let's say for letter grades. Here is some example for now:

import csv
import pandas as pd
import numpy as np
df = pd.read_csv('MOCK_DATA.csv')
df.head()

 

   id first_name last_name                     email  null field  blank_field
0   1      Paule    Tohill   ptohill0@macromedia.com       False         NaN
1   2       Rebe   Slyford  rslyford1@washington.edu        True         NaN
2   3   Angelita    Antoni        aantoni2@google.pl       False         NaN
3   4      Giffy      Dehm       gdehm3@berkeley.edu       False         NaN
4   5        Rob    Beadle       rbeadle4@taobao.com       False         NaN

I want to import the data to later change the blank_field column's type. I understand how to use SQLAlchemy with the Python connector.

df.to_sql(con=con, name='Grades', if_exists='replace', flavor='mysql')

Do I need to specify anything here to change the blank_field -column? How will Snowflake handle the NaN values?


回答1:


The column length will be the max of the longest value inserted or VARCHAR(16777216) if the column only contains NULL.

Then you can increase the size of the varchar column after creating the table but you can't decrease it. (Only very limited cases where you wouldn't be suited to using VARCHAR(MAX). Your only charged for what you actually store and the performance is based on the max length of the data, not the allowable limit).

https://docs.snowflake.net/manuals/sql-reference/sql/alter-table-column.html

create or replace temp table x as
select $1 as c1,$2 as c2
from values
('NaN',NULL)
;

desc table x;

create or replace temp table y as
select $1 as c1,$2 as c2
from values
('NaN',NULL)
,('A','B')
;

desc table y;

create or replace temp table z as
select $1 as c1,$2 as c2
from values
('A','B')
,('NaN',NULL)
;

desc table z;


来源:https://stackoverflow.com/questions/59636550/how-does-snowflake-handle-null-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!