Skip to content

fix: cast Postgre batch subquery values so updateBatch() and deleteBatch() accept mixed PHP types - #10601

Merged
paulbalandan merged 1 commit into
codeigniter4:developfrom
paulbalandan:postgre-batch-mixed-types
Oct 9, 2026
Merged

paulbalandan merged 1 commit into
codeigniter4:developfrom
paulbalandan:postgre-batch-mixed-types

Conversation

@paulbalandan

Copy link
Copy Markdown
Member

Description
Fixes #10599

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@carson-codeigniter4 carson-codeigniter4 Bot added the bug Verified issues on the current code behavior or pull requests that will fix them label Oct 6, 2026
@paulbalandan
paulbalandan force-pushed the postgre-batch-mixed-types branch 2 times, most recently from fe8ef19 to 22146f8 Compare October 6, 2026 10:02
@paulbalandan
paulbalandan force-pushed the postgre-batch-mixed-types branch from 22146f8 to ef96d2b Compare October 6, 2026 11:34
@michalsn
michalsn requested a balanced review from Copilot October 6, 2026 11:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Mapped or qualified columns can remain uncast, while enum, domain, and array metadata can generate invalid PostgreSQL casts.

Review effort: Balanced
Findings: 1 High severity · 2 Medium severity

Open (3)
What changed in this PR

Fixes PostgreSQL batch updates/deletes with mixed PHP value types by casting subquery values to target column types.

Changes:

  • Adds PostgreSQL value casting for batch operations.
  • Adds live database regression tests.
  • Documents the fix in the 4.7.5 changelog.

Base branch assumed to be develop. Static review performed; database validation remains with GitHub Actions.

File Description
system/​Database/​Postgre/​Builder.php Casts PostgreSQL batch subquery values.
tests/​system/​Database/​Live/​UpdateTest.php Tests mixed-type batch updates.
tests/​system/​Database/​Live/​DeleteTest.php Tests mixed-type batch deletes.
user_guide_src/​source/​changelogs/​v4.7.5.rst Records the bug fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread system/Database/Postgre/Builder.php Outdated
Comment thread system/Database/Postgre/Builder.php Outdated
Comment thread system/Database/Postgre/Builder.php Outdated

@michalsn michalsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casting delete constraint values to CHAR(n) can change which rows match. For example, with a CHAR(3) column, 'ABCD' is truncated to 'ABC', so deleteBatch() can delete the row containing 'ABC' even though the supplied value does not match it. The comparison should preserve the full input value.

@paulbalandan
paulbalandan force-pushed the postgre-batch-mixed-types branch from 4bc33aa to 0244f8c Compare October 8, 2026 19:08
@paulbalandan

Copy link
Copy Markdown
Member Author

Casting delete constraint values to CHAR(n) can change which rows match. For example, with a CHAR(3) column, 'ABCD' is truncated to 'ABC', so deleteBatch() can delete the row containing 'ABC' even though the supplied value does not match it. The comparison should preserve the full input value.

Fixed. The casting now uses BPCHAR whenever CHAR(n) was used.

@paulbalandan
paulbalandan force-pushed the postgre-batch-mixed-types branch from 0244f8c to dd4ebfd Compare October 8, 2026 19:21
Comment thread system/Database/Postgre/Builder.php Outdated
@paulbalandan
paulbalandan force-pushed the postgre-batch-mixed-types branch 2 times, most recently from e55b24e to ea06ab4 Compare October 9, 2026 10:27
@paulbalandan
paulbalandan force-pushed the postgre-batch-mixed-types branch from ea06ab4 to 0a8e4d7 Compare October 9, 2026 11:13
@paulbalandan
paulbalandan merged commit 483c57f into codeigniter4:develop Oct 9, 2026
60 checks passed
@paulbalandan
paulbalandan deleted the postgre-batch-mixed-types branch October 9, 2026 12:13
@paulbalandan

Copy link
Copy Markdown
Member Author

Thank you, @michalsn , for the reviews!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Verified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: [Postgre] updateBatch() fails for mixed PHP value types in a TEXT column

3 participants