Skip to content

Fix savepoint names that are reserved words - #6734

Open
Brar wants to merge 1 commit into
npgsql:mainfrom
Brar:tx/savepoint-names
Open

Brar wants to merge 1 commit into
npgsql:mainfrom
Brar:tx/savepoint-names

Conversation

@Brar

@Brar Brar commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

NpgsqlTransaction quoted a savepoint name only when it didn't look like a lowercase identifier, so a reserved word such as user or select went unquoted, and Save, Rollback and Release failed with 42601. Savepoint names are now always quoted, which keeps the meaning of every other name: a lowercase name means the same quoted or not. RequiresQuoting is gone.

The SQL changes with it: SAVEPOINT "foo" instead of SAVEPOINT foo, and the same for ROLLBACK TO SAVEPOINT and RELEASE SAVEPOINT, which shows in logs and traces. That's why this is a PR of its own rather than part of #6707, which otherwise sends the same SQL as before; whether it goes to the 10.0 hotfix branch is open.

Tests

  • TransactionTests.Savepoint_named_like_a_reserved_word (user, select): without this change both fail with 42601 at the SAVEPOINT; with it they pass.
  • Savepoint_prepends (mock) now expects SAVEPOINT "foo".
  • TransactionTests pass against PostgreSQL 18.6, in Debug and Release.

Dependencies and merge order

  • It depends on no other PR.

Fixes #6732

Copilot AI balanced review requested due to automatic review settings November 1, 2026 11:03
@Brar
Brar requested review from roji and vonzshik as code owners November 1, 2026 11:03

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.

🟡 Changes recommended

The test needs a PostgreSQL 19+ version guard before schema creation because its standard_conforming_strings=off configuration prevents connections from opening, so neither case exercises type loading.

1 open issue
What changed in this PR

Fixes #6732 by always quoting savepoint names, allowing reserved words such as user and select. The PR also includes the pending #6707 changes that centralize quoting and correct replication command formatting.

Changes:

  • Always quote names in savepoint creation, rollback, and release.
  • Add shared quoting helpers for replication commands and SQL, plus validation for required pgoutput option values.
  • Add regression tests for reserved words, replication names and options, and schema names containing backslashes.
File Description
test/​Npgsql.Tests/​TransactionTests.cs Tests reserved-word savepoints and updates expected SQL.
test/​Npgsql.Tests/​Replication/​ReplicationQuotingTests.cs Tests replication names, options, and publication quoting.
test/​Npgsql.Tests/​QuotingTests.cs Tests shared quoting helpers.
test/​Npgsql.Tests/​ConnectionTests.cs Tests schema quoting with backslash escapes enabled.
src/​Npgsql/​VolatileResourceManager.cs Quotes two-phase transaction identifiers as literals.
src/​Npgsql/​Util/​Statics.cs Adds shared identifier and literal quoting helpers.
src/​Npgsql/​Replication/​ReplicationConnection.cs Quotes slot names in read and drop commands.
src/​Npgsql/​Replication/​PhysicalReplicationConnection.cs Quotes physical replication slot names and rejects null names.
src/​Npgsql/​Replication/​PgOutput/​PgOutputReplicationOptions.cs Escapes publication names in option lists.
src/​Npgsql/​Replication/​Internal/​LogicalReplicationConnectionExtensions.cs Quotes logical replication inputs and validates required options.
src/​Npgsql/​PostgresDatabaseInfo.cs Quotes schema literals safely for type loading.
src/​Npgsql/​NpgsqlTransaction.cs Always quotes savepoint names and removes conditional quoting.
src/​Npgsql/​NpgsqlCommand.cs Uses the shared helper for named procedure arguments.

Review effort: Balanced

Comment thread test/Npgsql.Tests/ConnectionTests.cs Resolved
@Brar
Brar force-pushed the tx/savepoint-names branch from d5b5204 to f01591d Compare November 1, 2026 11:18
Copilot AI balanced review requested due to automatic review settings November 1, 2026 11:18

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.

🟢 Approval recommended

No active review issues remain for the savepoint and shared SQL quoting changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

NpgsqlTransaction quoted a savepoint name only when it didn't look like a
lowercase identifier, so a name such as user or select went unquoted, and
Save, Rollback and Release failed with 42601. Savepoint names are now always
quoted, which keeps the meaning of every other name. The SQL changes with it,
e.g. SAVEPOINT "foo" instead of SAVEPOINT foo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Brar
Brar force-pushed the tx/savepoint-names branch from f01591d to 984200e Compare November 1, 2026 13:38
Copilot AI balanced review requested due to automatic review settings November 1, 2026 13:38

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.

🟢 Approval recommended

No active review issues block the change to consistently quote savepoint names.

No open issues 🎉

Review effort: Balanced

This branch has not been deployed

No deployments
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.

Savepoint names that are reserved words fail with a syntax error

2 participants