Skip to content

fix(redshift): use a non-backslash LIKE escape so schema switching and filters work#1441

Merged
datlechin merged 1 commit into
mainfrom
worktree-fix-redshift-schema-escape
May 27, 2026
Merged

fix(redshift): use a non-backslash LIKE escape so schema switching and filters work#1441
datlechin merged 1 commit into
mainfrom
worktree-fix-redshift-schema-escape

Conversation

@datlechin
Copy link
Copy Markdown
Member

Fixes #1439.

Problem

Connecting to a Redshift database with multiple schemas, the schema selector is unavailable. fetchSchemas fails with:

ERROR: syntax error at or near "information_schema" ... in context
"NOT LIKE 'pg\_%' ESCAPE '\'  AND nspname <> 'information_schema"

Root cause

The schema query emits ... NOT LIKE 'pg\_%' ESCAPE '\'. Redshift forked from PostgreSQL 8.0.2, before standard_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). When fetchSchemas throws, 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 use NOT LIKE 'pg!_%' ESCAPE '!'. The literal-underscore match is kept so user schemas like pgvector/pgboss/pgcrypto are not wrongly excluded; the Redshift query also excludes catalog_history.
  • FilterSQLGenerator (macOS app + the TableProQuery package) and iOS SQLBuilder — the explicit-escape (PostgreSQL/Redshift) path emits ESCAPE '!' and escapes !, %, and _ in user input (escape char first). The MySQL implicit path is unchanged; for the package and iOS the escaping now branches on likeEscapeStyle so 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-backslash ESCAPE '\'; the existing schema-inclusion tests stay green.
  • FilterSQLGeneratorTests (macOS + package) — the PostgreSQL/Redshift dialect emits ESCAPE '!' and not ESCAPE '\', a literal ! in the value is self-escaped (a!b -> a!!b), and the MySQL/implicit path keeps backslash escaping with no ESCAPE clause.
  • Package tests pass: swift test --filter FilterSQLGeneratorTests (14/14).

Notes

swiftformat could not run locally: the repo .swiftformat uses --ifdefindent, which the installed swiftformat version rejects. Pre-existing and unrelated to this change.

@datlechin datlechin merged commit 76ebe4b into main May 27, 2026
2 of 3 checks passed
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

Successfully merging this pull request may close these issues.

Unable to switch schema in Redshift

1 participant