Skip to content

Add database adapter dialect helpers for PostgreSQL support - #41163

Open
mmustafasenoglu wants to merge 2 commits into
magento:2.4-developfrom
mmustafasenoglu:adapter-dialect-helpers
Open

Add database adapter dialect helpers for PostgreSQL support#41163
mmustafasenoglu wants to merge 2 commits into
magento:2.4-developfrom
mmustafasenoglu:adapter-dialect-helpers

Conversation

@mmustafasenoglu

@mmustafasenoglu mmustafasenoglu commented Aug 29, 2026

Copy link
Copy Markdown

What this PR does

Adds database adapter dialect helpers to enable PostgreSQL support via a separate module (Postgento). This is the core Magento changes needed - the actual PostgreSQL driver lives in a separate module: https://github.com/Genaker/postgento

Changes

AdapterInterface (lib/internal/Magento/Framework/DB/Adapter/AdapterInterface.php)

Added new methods:

  • getGroupConcatSql() - GROUP_CONCAT / string_agg equivalent
  • getFieldSql() - FIELD() / CASE equivalent for ORDER BY a fixed list
  • castToText() - Cast expression to text for UNION type alignment
  • castToNumeric() - Cast expression to numeric type for arithmetic
  • createTableLike() - CREATE TABLE new LIKE origin
  • createTemporaryTableFromSelect() - CREATE TEMPORARY TABLE from a SELECT

MySQL Implementation (lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php)

Implemented all new methods with MySQL-specific SQL.

Select (lib/internal/Magento/Framework/DB/Select.php)

Relaxed constructor type-hint from Pdo\Mysql to Zend_Db_Adapter_Abstract so any AdapterInterface implementation can call select().

TemporaryTableService (lib/internal/Magento/Framework/DB/TemporaryTableService.php)

Updated to use the new adapter method createTemporaryTableFromSelect().

BatchIterator (lib/internal/Magento/Framework/DB/Query/BatchIterator.php)

Fixed empty batch handling - keeps previous minValue when MAX() returns NULL to avoid binding null/empty string.

AbstractDb (lib/internal/Magento/Framework/Data/Collection/AbstractDb.php)

Replaced literal backticks with quoteIdentifier() for reserved words.

Setup Validators (setup/src/Magento/Setup/Validator/DbValidator.php, Installer.php, ConfigOptionsList.php)

Added --db-engine option support to pass through DbValidator/Installer.

Testing

  • Unit tests added for new dialect helpers in MysqlTest.php
  • TemporaryTableServiceTest updated to mock new adapter method
  • BatchIteratorTest added test for empty batch null handling

Related

Resolved issues:

  1. resolves [Issue] Add database adapter dialect helpers for PostgreSQL support #41177: Add database adapter dialect helpers for PostgreSQL support

This adds the following new methods to AdapterInterface and implements them in the MySQL adapter:
- getGroupConcatSql() - GROUP_CONCAT equivalent
- getFieldSql() - FIELD() / CASE equivalent for ORDER BY a fixed list
- castToText() - Cast expression to text for UNION type alignment
- castToNumeric() - Cast expression to numeric type for arithmetic
- createTableLike() - CREATE TABLE new LIKE origin
- createTemporaryTableFromSelect() - CREATE TEMPORARY TABLE from a SELECT

Also updates:
- Select constructor to accept Zend_Db_Adapter_Abstract instead of Pdo\Mysql
- TemporaryTableService to use the new adapter method
- BatchIterator to handle empty batch (null max) correctly
- AbstractDb to use quoteIdentifier() instead of literal backticks for reserved words
- Setup validators (DbValidator, Installer, ConfigOptionsList) to support --db-engine option

Part of magento#41148
Copilot AI lite review requested due to automatic review settings August 29, 2026 11:20
@m2-assistant

m2-assistant Bot commented Aug 29, 2026

Copy link
Copy Markdown

Hi @mmustafasenoglu. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.
❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

- MysqlTest: testDialectHelpers, testCreateTableLikeAndTemporaryFromSelect
- TemporaryTableServiceTest: updated to mock createTemporaryTableFromSelect
- BatchIteratorTest: testEmptyBatchDoesNotBindNullMinValue
@engcom-Bravo

Copy link
Copy Markdown
Contributor

@magento create issue

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

Labels

Priority: P3 May be fixed according to the position in the backlog. Progress: pending review Progress: review

Projects

Status: Pending Review

Development

Successfully merging this pull request may close these issues.

[Issue] Add database adapter dialect helpers for PostgreSQL support

3 participants