Describe the bug
The PostgreSQL dialect parser fails to parse valid PostgreSQL syntax when LIMIT appears after FOR UPDATE SKIP LOCKED, even though PostgreSQL accepts both clause orderings.
To Reproduce
use sqlparser::dialect::PostgreSqlDialect;
use sqlparser::parser::Parser;
fn main() {
let sql = r#"
SELECT "id", "status"
FROM "jobs"
WHERE "status" = 'pending'
ORDER BY "createdAt"
FOR UPDATE SKIP LOCKED
LIMIT 5
"#;
let dialect = PostgreSqlDialect {};
let result = Parser::parse_sql(&dialect, sql);
println!("{:?}", result);
}
Error:
sql parser error: Expected: end of statement, found: LIMIT at Line: X, Column: Y
Expected behavior
The parser should accept both clause orderings since PostgreSQL does:
- ✅
ORDER BY ... LIMIT 5 FOR UPDATE SKIP LOCKED (currently works)
- ❌
ORDER BY ... FOR UPDATE SKIP LOCKED LIMIT 5 (should also work)
Both are semantically identical in PostgreSQL.
Additional context
Tested on PostgreSQL
-- Both work in PostgreSQL 16:
SELECT * FROM jobs ORDER BY id LIMIT 5 FOR UPDATE SKIP LOCKED;
SELECT * FROM jobs ORDER BY id FOR UPDATE SKIP LOCKED LIMIT 5;
Describe the bug
The PostgreSQL dialect parser fails to parse valid PostgreSQL syntax when
LIMITappears afterFOR UPDATE SKIP LOCKED, even though PostgreSQL accepts both clause orderings.To Reproduce
Error:
Expected behavior
The parser should accept both clause orderings since PostgreSQL does:
ORDER BY ... LIMIT 5 FOR UPDATE SKIP LOCKED(currently works)ORDER BY ... FOR UPDATE SKIP LOCKED LIMIT 5(should also work)Both are semantically identical in PostgreSQL.
Additional context
FOR UPDATEshould come last, but PostgreSQL actually acceptsLIMITafter itTested on PostgreSQL