Skip to content

Quote reserved keywords in PostgreSQL function update fragments#242

Merged
jeremydmiller merged 2 commits intoJasperFx:masterfrom
MarkVDD:fix/quote-reserved-keywords
Apr 8, 2026
Merged

Quote reserved keywords in PostgreSQL function update fragments#242
jeremydmiller merged 2 commits intoJasperFx:masterfrom
MarkVDD:fix/quote-reserved-keywords

Conversation

@MarkVDD
Copy link
Copy Markdown
Contributor

@MarkVDD MarkVDD commented Apr 7, 2026

Description

The Problem

PostgreSQL reserved keywords (such as offset, limit, all, and select) cause a PostgresException (42601): syntax error when used as column names in generated PL/pgSQL functions. This happens because the SQL generator in TableColumn was using the raw Name property instead of a delimited identifier in the SET clause of update statements.

Example of failing SQL:
ON CONFLICT (id) DO UPDATE SET offset = EXCLUDED.offset; -- Syntax error near 'offset'

The Fix

Updated TableColumn.ToFunctionUpdate() to use the QuotedName property. This ensures that column assignments inside internal functions are always safely wrapped in double quotes (e.g., "offset" = p_offset).

Changes

  • Core: Modified Weasel.Postgresql.Tables.TableColumn.ToFunctionUpdate() to use quoted identifiers.
  • Unit Test: Added a Theory test to_function_update_should_quote_reserved_keywords in TableColumnTests.cs to verify string generation for common keywords.
  • Integration Test: Added a comprehensive Theory in detecting_table_deltas.cs that iterates through 70+ PostgreSQL reserved keywords to ensure they work across the full DDL lifecycle without triggering "infinite migrations" (false deltas).

Verification

  • Unit tests pass.
  • Integration tests with a live Postgres database pass.
  • Verified that detecting_table_deltas.no_delta remains green, ensuring no regression in schema comparison logic.

Related Marten PR: JasperFx/marten#4237

@jeremydmiller jeremydmiller merged commit 9c6ebf9 into JasperFx:master Apr 8, 2026
21 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.

2 participants