Untitled
unknown
plain_text
a year ago
1.2 kB
1
Indexable
Never
# ... (previous code) # Inside your main function, update the code where you construct insert_columns and insert_values for column_name, source_val in source_row.items(): if source_val is not None: if isinstance(source_val, str) and source_val.startswith('TO_DATE'): # If it already starts with TO_DATE, don't add TO_DATE again insert_columns.append(column_name) # Add the column name insert_values.append(source_val) elif is_datetime(source_val): # Add a function to check if the value is a datetime insert_columns.append(column_name) # Add the column name # Format datetime values using TO_DATE insert_values.append(f"TO_DATE('{source_val}', 'YYYY-MM-DD HH24:MI:SS')") else: insert_columns.append(column_name) # Add the column name insert_values.append(f"'{source_val}'") else: insert_columns.append(column_name) # Add the column name insert_values.append('NULL') # Construct the INSERT query with column names insert_query = f"INSERT INTO {schema_ext}.{table_name} ({', '.join(insert_columns)}) VALUES ({', '.join(insert_values)})"