SF_ACCOUNT, SF_USER and SF_PASSWORDjupyter notebook
In [1]:
import os
account=os.getenv('SF_ACCOUNT')
user=os.getenv('SF_USER')
password=os.getenv('SF_PASSWORD')
Set numpy=True in the connect string so that Python Connector fetches and converts TIMESTAMP data to datetime64 numpy data type.
In [2]:
from sqlalchemy import create_engine
from snowflake.sqlalchemy import URL
engine = create_engine(URL(
account=account,
user=user,
password=password,
database='testdb',
schema='public',
numpy=True,
))
In [3]:
engine.execute("""
CREATE OR REPLACE table TS_TABLE(
c1 timestamp,
c2 timestamp_ntz,
c3 timestamp_ltz,
c4 timestamp_tz)
""")
Out[3]:
Snowflake supports TIMESTAMP(9) by default; nanosecond precision is supported.
In [4]:
engine.execute("""
INSERT INTO TS_TABLE
select
current_timestamp(),
current_timestamp()::timestamp_ntz,
current_timestamp(),
'2016-06-20T12:34:56.123456789'
""")
Out[4]:
In [5]:
engine.execute("SELECT * FROM TS_TABLE").fetchall()
Out[5]:
In [6]:
from pandas import DataFrame, Series
import pandas as pd
In [7]:
df = pd.read_sql_query("SELECT * FROM TS_TABLE", engine)
In [8]:
df.info()
In [9]:
df
Out[9]:
Notice c4's value is reserved up to nanoseconds.
In [10]:
df2 = pd.read_sql_query("desc ts_table", engine)
In [11]:
df2
Out[11]:
In [12]:
df.c1
Out[12]:
In [13]:
df.c4
Out[13]:
In [ ]: