fix(redshift): use a non-backslash LIKE escape so schema switching and filters work#1441
Merged
Merged
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #1439.
Problem
Connecting to a Redshift database with multiple schemas, the schema selector is unavailable.
fetchSchemasfails with:Root cause
The schema query emits
... NOT LIKE 'pg\_%' ESCAPE '\'. Redshift forked from PostgreSQL 8.0.2, beforestandard_conforming_strings, and does not support it, so a backslash inside a'...'literal is always an escape character. The lone backslash in'\'escapes the closing quote, the string literal never terminates, and the parser fails at the next quote (information_schema). WhenfetchSchemasthrows, the schema list stays empty and the picker (which renders only when there is more than one schema) never appears.The same single-backslash
ESCAPE '\'is emitted for the PostgreSQL/Redshift dialect by the filter generators, so Redshift "contains / starts with / ends with" filters and table search break the same way.Fix
Use
!as the LIKE escape character wherever the PostgreSQL/Redshift dialect declares one.!is portable to both PostgreSQL and Redshift (AWS's own docs use non-backslash escape examples) and is not a LIKE wildcard.PostgreSQLSchemaQueries.swift— both schema queries useNOT LIKE 'pg!_%' ESCAPE '!'. The literal-underscore match is kept so user schemas likepgvector/pgboss/pgcryptoare not wrongly excluded; the Redshift query also excludescatalog_history.FilterSQLGenerator(macOS app + theTableProQuerypackage) and iOSSQLBuilder— the explicit-escape (PostgreSQL/Redshift) path emitsESCAPE '!'and escapes!,%, and_in user input (escape char first). The MySQL implicit path is unchanged; for the package and iOS the escaping now branches onlikeEscapeStyleso MySQL keeps its backslash behavior.MSSQL and Oracle emit the same Swift pattern but those engines tolerate it, so they are left alone. Switching Redshift to
svv_*system views (which would also surface Spectrum/datashare schemas) is a separate feature, not part of this fix.Tests
PostgreSQLSchemaFilterTests— asserts neither schema query contains a single-backslashESCAPE '\'; the existing schema-inclusion tests stay green.FilterSQLGeneratorTests(macOS + package) — the PostgreSQL/Redshift dialect emitsESCAPE '!'and notESCAPE '\', a literal!in the value is self-escaped (a!b->a!!b), and the MySQL/implicit path keeps backslash escaping with noESCAPEclause.swift test --filter FilterSQLGeneratorTests(14/14).Notes
swiftformat could not run locally: the repo
.swiftformatuses--ifdefindent, which the installed swiftformat version rejects. Pre-existing and unrelated to this change.