[Fix-18391] [Alert] Use lowercase table name in information_schema query for PostgreSQL compatibility#18392
[Fix-18391] [Alert] Use lowercase table name in information_schema query for PostgreSQL compatibility#18392njnu-seafish wants to merge 1 commit into
Conversation
…SQL compatibility
|
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
|
| <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' |
There was a problem hiding this comment.
Not all mysql will be case sensitive. This needs to distinguish between mysql and postgres.
There was a problem hiding this comment.
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:
- 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. - 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. - 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';).

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