Skip to content

fix: preserve psql FROM placeholder offsets - #773

Closed
dmakushin wants to merge 2 commits into
stephenafamo:mainfrom
dmakushin:fix/psql-update-from-placeholders
Closed

dmakushin wants to merge 2 commits into
stephenafamo:mainfrom
dmakushin:fix/psql-update-from-placeholders

Conversation

@dmakushin

@dmakushin dmakushin commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #772.

@atzedus

atzedus commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Hi @dmakushin, thanks for catching and fixing this bug! The current patch correctly resolves the immediate issue.

However, I'd like to suggest a slightly more robust architectural approach. Instead of just adjusting the start parameter at the call site, we could refactor the helper itself to align better with the rest of the bob codebase:

  1. Rename writeFromItemList to expressFromItems (to match the bob.Express* naming convention).
  2. Change the signature: Remove the args []any input parameter. The helper should only take the start index and return a new slice containing only the newly generated arguments.
  3. Update the callers (update.go, delete.go) to explicitly append the returned arguments to the main slice.

Why this approach is better:

  • Consistency: It makes the helper's contract identical to bob.ExpressIf and bob.ExpressSlice, which strictly return only newly created arguments.
  • Safety: Passing an args slice into a function, mutating/appending to it, and returning it back is a risky pattern in Go. It can lead to subtle, hard-to-track bugs if the underlying array of the caller's slice gets unexpectedly mutated.

Here is how the caller side would look with this approach:

fromItemArgs, err := expressFromItems(ctx, w, d, start+len(args), u.FromItems)
if err != nil {
    return nil, err
}
args = append(args, fromItemArgs...)

What do you think about refactoring it this way?

cc @stephenafamo to keep him in the loop regarding this architectural detail.

@dmakushin

Copy link
Copy Markdown
Contributor Author

Hi @atzedus , I have nothing against this plan. I've already forgotten the details, so it's hard for me to give a confident comments. Feel free to do whatever makes the most sense. I can close this PR for convenience.

@atzedus

atzedus commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Hi @dmakushin, following up on the discussion above - I've opened #786 with the same fix refactored per my suggestion (helper returns only new args, bob.Express*-style contract). Your original fix and tests are carried over with credit. This PR can be closed now, thanks again!

cc @stephenafamo

@dmakushin

Copy link
Copy Markdown
Contributor Author

Amazing! Thank you. Closing this one.

@dmakushin dmakushin closed this Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PostgreSQL UPDATE FROM double-counts preceding arguments when numbering placeholders

2 participants