-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[Fix-18391] [Alert] Use lowercase table name in information_schema query for PostgreSQL compatibility #18392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
njnu-seafish
wants to merge
1
commit into
apache:dev
Choose a base branch
from
njnu-seafish:Fix-18391
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 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 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.
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';).