uranusjr commented on code in PR #26661:
URL: https://github.com/apache/airflow/pull/26661#discussion_r979497653
##########
airflow/providers/postgres/hooks/postgres.py:
##########
@@ -270,10 +270,14 @@ def _generate_insert_sql(
raise ValueError("PostgreSQL ON CONFLICT upsert syntax
requires an unique index")
if isinstance(replace_index, str):
replace_index = [replace_index]
- replace_index_set = set(replace_index)
- replace_target = [
- "{0} = excluded.{0}".format(col) for col in target_fields if
col not in replace_index_set
- ]
- sql += f" ON CONFLICT ({', '.join(replace_index)}) DO UPDATE SET
{', '.join(replace_target)}"
+ on_conflict_str = f" ON CONFLICT ({', '.join(replace_index)})"
+ replace_target = [f for f in target_fields if f not in
replace_index]
+
+ if replace_target:
+ replace_target_str = ", ".join(f"{col} = excluded.{col}" for
col in replace_target)
+ sql += f"{on_conflict_str} DO UPDATE SET {replace_target_str}"
+ else:
+ sql += f"{on_conflict_str} DO NOTHING"
Review Comment:
It’s slightly weird to me that `replace=True, replace_index=()` triggers `ON
CONFLICT DO NOTHING` 🤔 We should probably list out all possible argument
combinations and try to figure out which behaviour is best for each.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]