From 783732d731e750feba052a398928593a015da1f6 Mon Sep 17 00:00:00 2001 From: Adam Ling Date: Mon, 17 Jul 2023 13:42:05 -0700 Subject: [PATCH] SNOW-735220: update documentation of pd_writer (#1642) --- src/snowflake/connector/pandas_tools.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/snowflake/connector/pandas_tools.py b/src/snowflake/connector/pandas_tools.py index 44f80eaff..17f4c060a 100644 --- a/src/snowflake/connector/pandas_tools.py +++ b/src/snowflake/connector/pandas_tools.py @@ -460,6 +460,15 @@ def pd_writer( ) -> None: """This is a wrapper on top of write_pandas to make it compatible with to_sql method in pandas. + Notes: + Please note that when column names in the pandas DataFrame are consist of strictly lower case letters, column names need to + be enquoted, otherwise `ProgrammingError` will be raised. + + This is because `snowflake-sqlalchemy` does not enquote lower case column names when creating the table, but `pd_writer` enquotes the columns by default. + the copy into command looks for enquoted column names. + + Future improvements will be made in the snowflake-sqlalchemy library. + Example usage: import pandas as pd from snowflake.connector.pandas_tools import pd_writer @@ -467,6 +476,10 @@ def pd_writer( sf_connector_version_df = pd.DataFrame([('snowflake-connector-python', '1.0')], columns=['NAME', 'NEWEST_VERSION']) sf_connector_version_df.to_sql('driver_versions', engine, index=False, method=pd_writer) + # when the column names are consist of only lower case letters, enquote the column names + sf_connector_version_df = pd.DataFrame([('snowflake-connector-python', '1.0')], columns=['"name"', '"newest_version"']) + sf_connector_version_df.to_sql('driver_versions', engine, index=False, method=pd_writer) + Args: table: Pandas package's table object. conn: SQLAlchemy engine object to talk to Snowflake.