Skip to content
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

Incorrect PostgreSQL escaping for schema name exclusion in query #6404

Open
amillet opened this issue May 16, 2024 · 1 comment
Open

Incorrect PostgreSQL escaping for schema name exclusion in query #6404

amillet opened this issue May 16, 2024 · 1 comment

Comments

@amillet
Copy link

amillet commented May 16, 2024

Hello,

I've encountered an issue related to PostgreSQL escaping within a query that is intended to exclude certain schema names (for example pgmain), specifically those starting with pg_. The query in question does not correctly escape the underscore character. Here's the problematic query:

SELECT schema_name
FROM   information_schema.schemata
WHERE  schema_name NOT LIKE 'pg\_%'
AND    schema_name != 'information_schema'

According to the PostgreSQL documentation (https://www.postgresql.org/docs/current/ddl-schemas.html), schema names beginning with pg_ are reserved for system. The documentation implies that to correctly escape the underscore in SQL queries, a double backslash (\\) should be used instead of a single backslash (\).

Therefore, the corrected version of the query should be:

SELECT schema_name
FROM   information_schema.schemata
WHERE  schema_name NOT LIKE 'pg\\_%'
AND    schema_name != 'information_schema'

Do you think we can modify the impacted code? I believe there are several queries involved.

@greg0ire
Copy link
Member

Yes. Please send a PR, with tests demonstrating the bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants