Skip to content

Commit

Permalink
Fix: preserve identifiers in postgres merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao committed Oct 6, 2023
1 parent ae27e46 commit d9bfaa7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion sqlglot/dialects/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def _remove_target_from_merge(expression: exp.Expression) -> exp.Expression:

for when in expression.expressions:
when.transform(
lambda node: exp.column(node.name)
lambda node: exp.column(node.this)
if isinstance(node, exp.Column) and normalize(node.args.get("table")) in targets
else node,
copy=False,
Expand Down
6 changes: 3 additions & 3 deletions tests/dialects/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,10 +648,10 @@ def test_postgres(self):
},
)
self.validate_all(
"merge into x as x using (select id) as y on a = b WHEN matched then update set X.a = y.b",
"""merge into x as x using (select id) as y on a = b WHEN matched then update set X."A" = y.b""",
write={
"postgres": "MERGE INTO x AS x USING (SELECT id) AS y ON a = b WHEN MATCHED THEN UPDATE SET a = y.b",
"snowflake": "MERGE INTO x AS x USING (SELECT id) AS y ON a = b WHEN MATCHED THEN UPDATE SET X.a = y.b",
"postgres": """MERGE INTO x AS x USING (SELECT id) AS y ON a = b WHEN MATCHED THEN UPDATE SET "A" = y.b""",
"snowflake": """MERGE INTO x AS x USING (SELECT id) AS y ON a = b WHEN MATCHED THEN UPDATE SET X."A" = y.b""",
},
)
self.validate_all(
Expand Down

0 comments on commit d9bfaa7

Please sign in to comment.