Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
748 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 is not None:
        if isinstance(source_val, datetime):
            # Convert the datetime to the appropriate format using TO_DATE
            formatted_datetime = source_val.strftime("TO_DATE('%Y-%m-%d %H:%M:%S', 'YYYY-MM-DD HH24:MI:SS')")
            insert_values.append(formatted_datetime)
        else:
            insert_values.append(f"'{source_val}'")
    else:
        insert_values.append('NULL')

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