Skip to content

Fix collation/ctype query error for non-default LC_COLLATE (#9798)#10040

Open
dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:fix-9798-collation-ctypes
Open

Fix collation/ctype query error for non-default LC_COLLATE (#9798)#10040
dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:fix-9798-collation-ctypes

Conversation

@dpage

@dpage dpage commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #9798.

Creating/editing a database with a non-default LC_COLLATE/LC_CTYPE (e.g. LC_COLLATE=C) failed with more than one row returned by a subquery used as an expression, which locked the collation input.

Root cause: get_ctypes.sql (PG 16+ and 17+) wrapped a multi-row UNION inside a scalar subquery in a CASE ... ELSE branch. For a non-ICU database where datcollate != datctype, that branch returns two rows → scalar-subquery error.

Fix: rewrite as a flat UNION of guarded SELECTs returning cname rows (keyed on datlocprovider), which is exactly what the get_ctypes handler already expects (it iterates rset['rows']). This mirrors the pre-16 default template's flat shape.

Changes

  • databases/sql/16_plus/get_ctypes.sql, databases/sql/17_plus/get_ctypes.sql
  • Release note (9.16)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation

    • Added release notes for pgAdmin 4 version 9.16 with supported database server versions and bundled utilities information.
  • Bug Fixes

    • Fixed an issue with LC_COLLATE/LC_CTYPE editing and creation failure.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@dpage, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 7 minutes and 24 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 83726e63-53f9-407b-a0a7-4f378a0b3493

📥 Commits

Reviewing files that changed from the base of the PR and between a5cd46a and f1a2cf2.

📒 Files selected for processing (3)
  • docs/en_US/release_notes_9_16.rst
  • web/pgadmin/browser/server_groups/servers/databases/templates/databases/sql/16_plus/get_ctypes.sql
  • web/pgadmin/browser/server_groups/servers/databases/templates/databases/sql/17_plus/get_ctypes.sql

Walkthrough

This PR introduces pgAdmin 4 version 9.16 release documentation and fixes a critical SQL bug affecting database collation field handling. A nested CASE subquery was replaced with explicit UNION branches in PostgreSQL 16+ and 17+ query templates to resolve collation input lockup when LC_COLLATE=C is used.

Changes

pgAdmin 9.16 Release with Collation Provider Fix

Layer / File(s) Summary
Release notes documentation for v9.16
docs/en_US/release_notes.rst, docs/en_US/release_notes_9_16.rst
Release notes toctree linked to new v9.16 document. New release notes file documents v9.16 with supported PostgreSQL/EDB versions 13–18, bundled utilities v18.2, and bug fix for issue #9798 (LC_COLLATE/LC_CTYPE editing/creation failure).
Database collation provider SQL query fixes
web/pgadmin/browser/server_groups/servers/databases/templates/databases/sql/16_plus/get_ctypes.sql, web/pgadmin/browser/server_groups/servers/databases/templates/databases/sql/17_plus/get_ctypes.sql
get_ctypes queries refactored from nested CASE WHEN datlocprovider = 'i' subqueries to explicit UNION branches. Returns daticulocale for ICU provider and datcollate/datctype for other providers, eliminating "more than one row returned by a subquery" error when LC_COLLATE=C is set.

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix collation/ctype query error for non-default LC_COLLATE (#9798)' directly and specifically summarizes the main change—fixing a SQL query error related to collation/ctype handling.
Linked Issues check ✅ Passed The PR addresses all coding requirements from issue #9798: the SQL queries in get_ctypes.sql (16_plus and 17_plus) were rewritten to use flat UNION statements instead of scalar subqueries, eliminating the multi-row subquery error.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing issue #9798: SQL rewrites in two get_ctypes.sql files, a new release notes entry (9.16), and a reference to the fixed issue. No unrelated changes detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dpage dpage force-pushed the fix-9798-collation-ctypes branch 2 times, most recently from bb8fa3d to 4025de4 Compare June 9, 2026 11:36
…rg#9798

get_ctypes.sql for PG 16+/17+ wrapped a multi-row UNION inside a scalar
subquery in a CASE ELSE branch. When the database is not ICU-based and
datcollate != datctype (e.g. LC_COLLATE=C with a different ctype), the
scalar subquery returned two rows -> "more than one row returned by a
subquery used as an expression", which locked the collation input.
Rewrite as a flat UNION of guarded SELECTs returning cname rows, matching
how the handler already consumes the result (a list of rows).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dpage dpage force-pushed the fix-9798-collation-ctypes branch from 4025de4 to f1a2cf2 Compare June 9, 2026 11:37
@asheshv asheshv requested a review from Copilot June 10, 2026 14:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes a PostgreSQL 16+ / 17+ SQL-template bug that could raise “more than one row returned by a subquery used as an expression” when a database has non-default LC_COLLATE/LC_CTYPE, preventing pgAdmin from populating/unlocking the collation/ctype fields in the database create/edit UI.

Changes:

  • Rewrote get_ctypes.sql for PG 16+ and 17+ to return rows via guarded UNION selects (instead of a scalar subquery in a CASE expression).
  • Added a 9.16 release note entry referencing Issue #9798.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
web/pgadmin/browser/server_groups/servers/databases/templates/databases/sql/16_plus/get_ctypes.sql Avoids scalar-subquery multi-row errors by returning locale/ctype values as a simple row set.
web/pgadmin/browser/server_groups/servers/databases/templates/databases/sql/17_plus/get_ctypes.sql Same fix as 16+, using the PG 17+ column layout.
docs/en_US/release_notes_9_16.rst Documents the bug fix in the 9.16 release notes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

Using LC_COLLATE=C locks collaction input when creating/editing database due to SQL error

2 participants