Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
724 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 ' ' in source_val:  # Check if the value contains a space (indicating a datetime string)
            formatted_datetime = f"TO_DATE('{source_val}', 'YYYY-MM-DD HH24:MI:SS')"  # Format as TO_DATE
            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 += ")"