Skip to content

PostgreSQL: Support FOR NO KEY UPDATE and FOR KEY SHARE - #2788

Closed
abhinav-phi wants to merge 1 commit into
apache:mainfrom
abhinav-phi:fix/2778-row-locking-clauses
Closed

abhinav-phi wants to merge 1 commit into
apache:mainfrom
abhinav-phi:fix/2778-row-locking-clauses

Conversation

@abhinav-phi

Copy link
Copy Markdown

FOR NO KEY UPDATE and FOR KEY SHARE are valid PostgreSQL row locking strengths but were rejected:

sql parser error: Expected: one of UPDATE or SHARE, found: NO
sql parser error: Expected: one of UPDATE or SHARE, found: KEY

Add LockType::NoKeyUpdate / LockType::KeyShare, display them as NO KEY UPDATE / KEY SHARE, and parse them in parse_lock before the existing OF / NOWAIT / SKIP LOCKED handling.

Grammar: https://www.postgresql.org/docs/current/sql-select.html#SQL-FOR-UPDATE-SHARE

Tests cover both forms with OF and wait policies in PostgreSQL and Generic, and incomplete forms are rejected. Added fuzz seed fuzz/fuzz_seeds/postgres_2778_row_locking.sql.

Validation: cargo test --all-features, cargo fmt --all -- --check, cargo clippy --all-targets --all-features -- -D warnings.

Fixes #2778.
AI-ASSISTED: yes. human reviewer: @abhinav-phi.

Add LockType::NoKeyUpdate and LockType::KeyShare, parse both row-locking
strengths in parse_lock, and cover them with PostgreSQL/Generic round-trip
tests, error-path tests, and a fuzz seed.

Refs apache#2778

@slopgobblercobbler slopgobblercobbler 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.

Audited the PostgreSQL row-locking strength extension in src/ast/query.rs and src/parser/mod.rs:

  • AST representation and Display roundtrip:
    • Adding LockType::NoKeyUpdate and LockType::KeyShare accurately models PostgreSQL's row-level locking strengths (FOR NO KEY UPDATE and FOR KEY SHARE).
    • fmt::Display outputs "NO KEY UPDATE" and "KEY SHARE", integrating seamlessly with LockClause formatting (write!(f, "FOR {}", self.lock_type)) to achieve byte-exact roundtrip serialization.
  • Parser lookahead and error reporting:
    • Lookahead sequencing in parse_lock checks NO -> [KEY, UPDATE] and KEY -> SHARE before falling back to [UPDATE, SHARE]. This prevents ambiguous keyword matching while providing precise diagnostics on truncated or mismatched clauses (e.g. FOR NO KEY SHARE rejecting on SHARE rather than failing generically).
    • Trailing clauses (OF, NOWAIT, SKIP LOCKED) execute after lock_type resolution, correctly supporting compositions such as FOR NO KEY UPDATE OF t SKIP LOCKED and FOR KEY SHARE OF t NOWAIT.
  • Dialect behavior:
    • Both PostgreSQL and Generic dialects correctly accept the new clauses without altering syntax rules for other database engines.
  • Test and fuzz coverage:
    • Unit tests comprehensively verify roundtrip formatting, AST structure (lock.of, lock.nonblock), and negative test cases for incomplete or invalid token sequences.
    • Adding fuzz/fuzz_seeds/postgres_2778_row_locking.sql ensures ongoing fuzzer validation.

Clean, idiomatic Rust AST contribution that closes a noticeable Postgres syntax gap with zero breaking changes.

@alamb alamb added the Prolific Author author opened PRs or issues in more than 20 repositories in the last 30 days label Nov 2, 2026
@alamb

alamb commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Thank you for the contribution. The change may well be correct, but I am closing this PR under the DataFusion AI policy, which also applies to sqlparser-rs.

Maintainer review time is the scarcest resource in this project. This account has opened more than 30 PRs across many repositories in the last month, which looks like GitHub "merge-maxxing" (collecting merged PRs) rather than work on a project the author uses. Several similar PRs have been closed elsewhere (for example boa-dev/temporal#760, OSGeo/grass#8126, OSGeo/grass#8127, python/cpython#158491 and wagtail/wagtail#14670), and the only review on this PR came from another account whose PRs we have closed as AI-generated. That suggests the changes aren't coming from someone who uses sqlparser-rs, and that no human will be around to discuss review feedback and maintain the code. Reviewing PRs like this costs us more time than it saves.

If you do use sqlparser-rs and this fix matters to you, please pick the one change you care most about. Then open a focused PR with a short description in your own words, one you have reviewed and understand, and we'd be happy to help with review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PostgreSQL Prolific Author author opened PRs or issues in more than 20 repositories in the last 30 days

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PostgreSQL: support FOR NO KEY UPDATE and FOR KEY SHARE row-locking clauses

3 participants