fix(postgresql): Use template0 to fix database creation failure#950
fix(postgresql): Use template0 to fix database creation failure#950datlechin merged 1 commit intoTableProApp:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d616a51db5
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| } | ||
| let escapedCollation = collation.replacingOccurrences(of: "'", with: "''") | ||
| query += " LC_COLLATE '\(escapedCollation)'" | ||
| query += " TEMPLATE 'template0' LC_COLLATE '\(escapedCollation)'" |
There was a problem hiding this comment.
Use identifier syntax for TEMPLATE in CREATE DATABASE
The new SQL fragment sets the template as TEMPLATE 'template0', but PostgreSQL expects a template database name (identifier), e.g. TEMPLATE template0 (or TEMPLATE = template0), not a string literal. In createDatabase, this path is taken whenever a collation is provided, so PostgreSQL database creation can fail with a syntax error instead of fixing the collation issue this change targets.
Useful? React with 👍 / 👎.
Summary
Use template0 as the template database to prevent collation‑mismatch failures when creating a new PostgreSQL database.
Root cause
When creating a database, PostgreSQL defaults to copying template1. The new database must have LC_COLLATE and LC_CTYPE values that exactly match those of the template database. In tablepro, LC_COLLATE can only choose one from
en_US.UTF-8/C/POSIX/C.UTF-8, which leads to not being able to match the LC_COLLATE in template1 completely. This causes an error.Test plan
closed #927