Skip to content

fix: strip function parentheses from result column names (#75)#76

Merged
erans merged 4 commits into
mainfrom
feature/column-name-sanitization
May 8, 2026
Merged

fix: strip function parentheses from result column names (#75)#76
erans merged 4 commits into
mainfrom
feature/column-name-sanitization

Conversation

@erans
Copy link
Copy Markdown
Owner

@erans erans commented May 8, 2026

Summary

Fixes #75 — PostgreSQL returns function names as column names (e.g., version), but SQLite returns the full expression (e.g., version()). This breaks clients like pgAdmin4 that expect PostgreSQL-compatible column names.

Changes

  • New sanitize_column_name() function (src/query/column_sanitizer.rs) — strips everything from the first ( onward, turning version()version, count(*)count, max(id)max, etc.
  • Applied at all 16 stmt.column_name(i) call sites across 5 files — db_handler.rs, fast_path.rs, query_interceptor.rs, statement_pool.rs, read_only_optimizer.rs
  • Updated get_aggregate_return_type_with_query() to handle bare function names (without parentheses) — since column names now arrive sanitized, the type inference logic needs to match json_extract not just json_extract(...).

Testing

  • 11 unit tests for sanitize_column_name
  • All existing tests pass (except pre-existing test_now_function failure unrelated to this change)
  • cargo check, cargo build, cargo clippy all clean

erans added 4 commits May 8, 2026 13:18
…olumn names

Fixes GitHub #75 - pgAdmin4 breaks because SQLite returns column names
like 'version()' instead of 'version'. The sanitizer strips everything
from the first '(' onward, matching PostgreSQL behavior.
After sanitizing column names by stripping parentheses, function names
like 'json_extract' arrive without parens instead of 'json_extract(...)'.
Add exact-match handling for known function names (without parens) before
falling back to query-based alias detection.
@erans erans merged commit 3b9c49f into main May 8, 2026
1 check passed
@erans erans deleted the feature/column-name-sanitization branch May 8, 2026 23:17
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.

Function parenthesing

1 participant