Skip to content

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

Open
paulbalandan wants to merge 1 commit into
codeigniter4:developfrom
paulbalandan:postgre-batch-mixed-types
Open

paulbalandan wants to merge 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 on lines +627 to +631
$column = array_search($key, $constraints, true);

return sprintf(
'%s %s',
$this->cast((string) $index, $this->getFieldType($table, is_string($column) ? $column : $key)),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This form does not work on develop either: the delete WHERE clause already prefixes the key with the table, so a qualified key yields "type_test"."type_test"."type_text". The example cited is the MySQL updateBatch sample. Supporting qualified mapped keys is a separate change.

@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.

This branch has not been deployed

No deployments
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