How should I replace the NaN or None values for inserting timestamptz columns? #63
-
| Driver version2.0.888 Redshift versionPostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.31651 Client Operating SystemCentOS 7.9 on AWS EC2 Python versionpython 3.6 Problem descriptionI can't insert empty values to timestamptz columns. This is flow of my logic; 
 Then it returns an error like this; All columns are nullable. | 
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
| Hey @ykparkwixon, You'll want to replace NaN values with  import redshift_connector
import pandas as pd
import numpy as np
df = pd.DataFrame([[np.nan],
                   [np.nan],
                   [np.nan],
                   [None]],
                  columns=list("a"))
df = df.replace({np.nan: None})
with redshift_connector.connect(...) as conn:
    with conn.cursor() as cursor:
        cursor.execute("create table test (c1 timestamptz)")
        cursor.write_dataframe(df, 'test')
        cursor.execute("select * from test")
        data = cursor.fetchall()
        print(data) | 
Beta Was this translation helpful? Give feedback.
Hey @ykparkwixon,
You'll want to replace NaN values with
None. I've run the following example locally without issuereference