ARTICLE AD BOX
I'm reading from a csv file that looks like this:
"id_field","last_updated_date" "123456",2021-08-07 16:26:45.299And creating a dataframe using:
df = pd.read_csv(file_path)I'm getting metadata about the table columns and using that to create a dtype map that I will use when writing to my oracle database table
metadata = MetaData() table = Table( quoted_name(table_name, True), metadata, schema=quoted_name(self.schema, True), autoload_with=self.engine ) dtype_map = {} for col in table.columns: col_name = col.name col_type = col.type dtype_map[col_name] = col_typeI'm then trying to write into my oracle table using:
df.to_sql( name=quoted_name(table_name, True), con=self.engine, schema=quoted_name(self.schema, True), if_exists=if_exists, index=False, dtype=dtype_map, )where self.engine is a sqlalchemy engine.
But i'm getting the following error from oracle: '(oracledb.exceptions.DatabaseError) ORA-00904: "LAST_UPDATED_DATE": invalid identifier\nHelp: https://docs.oracle.com/error-help/db/ora-00904/'
I believe this is because when the to_sql generates insert statements it does so without quoting the column names.
'INSERT INTO "my_schema"."my_table" (id_field, last_updated_date) VALUES (:id_field, :last_updated_date)'and because my column names in oracle are lowercase it complains. Here's my table DDL
CREATE TABLE "my_schema"."my_table" ( "id_field" VARCHAR2(50 CHAR), "last_updated_date" TIMESTAMP (6) ) TABLESPACE "USERS" ;Is it possible to get the insert statement to preserve column casing by quoting the column names.
