Find a cleaner solution for the return_skipped_upsert? logic introduced in #626

未关闭
#628 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
40/100
Issue 类型
重构
描述清晰度
需要澄清
活跃度
冷清
技术栈
elixir, postgresql
领域
databases

调研方向

首先检查 PR #626 和当前的 return_skipped_upsert? 逻辑,然后跟踪 bulk_upserts 如何构建其 PostgreSQL upsert 语句,以及 Ecto 如何处理 :returning 选项。将额外查询和数据处理的方法与尝试过的 upsert 条件标记进行比较;完成标准是找到一种受支持且可维护的方法,在不使用当前 workaround 的情况下识别被跳过的记录。

由索引模型根据 Issue 内容生成。

描述

enhancement
Code of Conduct
  • I agree to follow this project's Code of Conduct
AI Policy
  • I agree to follow this project's AI Policy, or I agree that AI was not used while creating this issue.
Is your feature request related to a problem? Please describe.

https://github.com/ash-project/ash_postgres/pull/626 adds support for returning skipped records from bulk_upserts. but we need to do an extra query and some data wrangling to achieve it.

Describe the solution you'd like

I tried doing it as part of the upsert statement by adding the upsert_condition logic to the update statement and add a marker to the return values to check if one of the inserts was actually skipped because of the condition logic.

  1. CASE WHEN in DO UPDATE SET was successfully implemented - the conditional logic works, SQL generates correctly
  2. The goal was to add the condition to RETURNING like:
    RETURNING id, price, (price != EXCLUDED.price) AS met_upsert_condition
  3. PostgreSQL supports this - expressions in RETURNING are valid SQL
  4. But Ecto doesn't expose a way to do it:
    - The :returning option flows through quote_names() which calls quote_name/1 on each item
    - quote_name/1 only has function clauses for atoms and strings - it quotes them as identifiers
    - If {:unsafe_fragment, "..."} is passed (like :conflict_target supports), it crashes with FunctionClauseError because there's no matching clause
    - If a plain string like "(condition) AS met" is passed, it gets quoted as "(condition) AS met" which is an invalid identifier
Describe alternatives you've considered

No response

Additional context

No response

主要语言
Elixir
星标
191
派生
186
平均合并
16 小时 4 分钟
30 天内合并 PR
17

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ash-project/ash_postgres 的其他 Issue

查看 ash-project/ash_postgres 的全部 Issue

相似的 Issue

更多 Elixir Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。