Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
930 B
2
Indexable
Never
# Generate an INSERT query dynamically
insert_query = f"INSERT INTO {schema_ext}.{table_name} ("
insert_columns = []
insert_values = []

for column_name, source_val in source_row.items():
    if source_val == 'None':
        insert_columns.append(column_name)
        insert_values.append('NULL')
    else:
        insert_columns.append(column_name)
        if column_name in ('created_by', 'updated_by', 'end_date'):
            # Format date columns as TO_DATE('YYYY-MM-DD HH24:MI:SS', 'YYYY-MM-DD HH24:MI:SS')
            insert_values.append(f"TO_DATE('{source_val}', 'YYYY-MM-DD HH24:MI:SS')")
        else:
            insert_values.append(f"'{source_val}'")

insert_query += ", ".join(insert_columns)
insert_query += ") VALUES ("
insert_query += ", ".join(insert_values)
insert_query += ")"

# Execute the INSERT query
try:
    print(insert_query)
    # cursor_ext.execute(insert_query)
except Exception as e:
    continue