Skip to content

[Fix-18391] [Alert] Use lowercase table name in information_schema query for PostgreSQL compatibility#18392

Open
njnu-seafish wants to merge 1 commit into
apache:devfrom
njnu-seafish:Fix-18391
Open

[Fix-18391] [Alert] Use lowercase table name in information_schema query for PostgreSQL compatibility#18392
njnu-seafish wants to merge 1 commit into
apache:devfrom
njnu-seafish:Fix-18391

Conversation

@njnu-seafish

Copy link
Copy Markdown
Contributor

Was this PR generated or assisted by AI?

NO

Purpose of the pull request

close #18391

Brief change log

Use lowercase table name in information_schema query for PostgreSQL compatibility.

Verify this pull request

This pull request is code cleanup without any test coverage.

(or)

This pull request is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(or)

Pull Request Notice

Pull Request Notice

If your pull request contains incompatible change, you should also add it to docs/docs/en/guide/upgrade/incompatible.md

@njnu-seafish

Copy link
Copy Markdown
Contributor Author

I noticed the information_schema SQL style is a bit inconsistent right now. PostgreSQL uses lowercase table names, but MySQL mixes upper and lower case (because MySQL is case-insensitive). Should we unify everything to lowercase for better cross-database compatibility? @SbloodyS

screenshot_1782991531321

<mapper namespace="org.apache.dolphinscheduler.dao.mapper.PluginDefineMapper">
<select id="checkTableExist" resultType="int">
select count(*) from information_schema.TABLES where table_name = 't_ds_plugin_define'
select count(*) from information_schema.tables where table_name = 't_ds_plugin_define'

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.

Not all mysql will be case sensitive. This needs to distinguish between mysql and postgres.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not all mysql will be case sensitive. This needs to distinguish between mysql and postgres.

I've tested this on both MySQL 5.x and 8.x, and both information_schema.tables and information_schema.TABLES execute without any issues.

I don't have the environment to test every version of MySQL and PostgreSQL, so I asked an AI this question: For information_schema.tables and information_schema.TABLES, which casing should I use to ensure compatibility with both MySQL and PostgreSQL?

-------------------------------Here is the AI's answer:-----------------------------------
To ensure compatibility across both MySQL and PostgreSQL, it is highly recommended to use lowercase (i.e., information_schema.tables).
Here is the breakdown of why lowercase is the best choice:

  1. PostgreSQL's Default Behavior
    PostgreSQL automatically folds (converts) unquoted identifiers to lowercase. So, whether you write information_schema.tables or information_schema.TABLES, PostgreSQL treats them exactly the same. Using lowercase aligns perfectly with PostgreSQL's internal logic and standard conventions.
  2. MySQL's Compatibility
    MySQL fully supports lowercase information_schema.tables. While MySQL 8.0 treats INFORMATION_SCHEMA as case-insensitive, older versions (like MySQL 5.x on Linux) can be case-sensitive depending on the OS file system and the lower_case_table_names setting. Lowercase is universally safe.
  3. The Risk of Using Uppercase
    While uppercase works in most cases, it can cause issues if someone accidentally uses double quotes. In PostgreSQL, double quotes force strict case sensitivity (e.g., "INFORMATION_SCHEMA" is different from information_schema). Sticking to lowercase avoids this trap entirely.
    Best Practice for Cross-Database Scripts:
    When writing SQL that needs to run on multiple database engines, always use lowercase for both the schema name, table names, and column names (e.g., SELECT table_name FROM information_schema.tables WHERE table_schema = 'my_db';).

@njnu-seafish njnu-seafish requested a review from SbloodyS July 3, 2026 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] [Alert] The AlertServer service may fail to start in specific PostgreSQL environments due to incompatible SQL syntax.

2 participants