Skip to content

fix(postgresql): Use template0 to fix database creation failure#950

Merged
datlechin merged 1 commit intoTableProApp:mainfrom
stolenzc:fix/pg_create
Apr 30, 2026
Merged

fix(postgresql): Use template0 to fix database creation failure#950
datlechin merged 1 commit intoTableProApp:mainfrom
stolenzc:fix/pg_create

Conversation

@stolenzc
Copy link
Copy Markdown
Contributor

@stolenzc stolenzc commented Apr 30, 2026

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

  • Test all LC_COLLATE sets to create a database and verify the final created data LC_COLLATE value

closed #927

Copy link
Copy Markdown
Member

@datlechin datlechin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@datlechin datlechin merged commit 6c69fab into TableProApp:main Apr 30, 2026
1 check passed
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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)'"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

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.

can not create new postgresql database

2 participants