Skip to content

Commit 44eb58d

Browse files
Copilotjason810496
andauthored
Fix ambiguous column references in delete and archive SQL statements (#27)
* Initial plan * Fix ambiguous column references in delete_batch and archive_batch Co-authored-by: jason810496 <[email protected]> * Add aliases to delete and archive statements to avoid ambiguity Co-authored-by: jason810496 <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: jason810496 <[email protected]>
1 parent e5d7c75 commit 44eb58d

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

pgmq_sqlalchemy/operation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def _get_delete_statement(
213213
queue_name: str, msg_id: int
214214
) -> Tuple[str, Dict[str, Any]]:
215215
"""Get statement and params for delete."""
216-
return "select pgmq.delete(:queue_name, :msg_id);", {
216+
return "select pgmq.delete(:queue_name, :msg_id) as deleted;", {
217217
"queue_name": queue_name,
218218
"msg_id": msg_id,
219219
}
@@ -224,7 +224,7 @@ def _get_delete_batch_statement(
224224
) -> Tuple[str, Dict[str, Any]]:
225225
"""Get statement and params for delete_batch."""
226226
return (
227-
"select msg_id from unnest(CAST(:msg_ids AS bigint[])) as msg_id where pgmq.delete(:queue_name, msg_id);",
227+
"select t.msg_id from unnest(CAST(:msg_ids AS bigint[])) as t(msg_id) where pgmq.delete(:queue_name, t.msg_id);",
228228
{"queue_name": queue_name, "msg_ids": msg_ids},
229229
)
230230

@@ -233,7 +233,7 @@ def _get_archive_statement(
233233
queue_name: str, msg_id: int
234234
) -> Tuple[str, Dict[str, Any]]:
235235
"""Get statement and params for archive."""
236-
return "select pgmq.archive(:queue_name, :msg_id);", {
236+
return "select pgmq.archive(:queue_name, :msg_id) as archived;", {
237237
"queue_name": queue_name,
238238
"msg_id": msg_id,
239239
}
@@ -244,7 +244,7 @@ def _get_archive_batch_statement(
244244
) -> Tuple[str, Dict[str, Any]]:
245245
"""Get statement and params for archive_batch."""
246246
return (
247-
"select msg_id from unnest(CAST(:msg_ids AS bigint[])) as msg_id where pgmq.archive(:queue_name, msg_id);",
247+
"select t.msg_id from unnest(CAST(:msg_ids AS bigint[])) as t(msg_id) where pgmq.archive(:queue_name, t.msg_id);",
248248
{"queue_name": queue_name, "msg_ids": msg_ids},
249249
)
250250

0 commit comments

Comments
 (0)