Skip to content

PostgreSqlDialect rejects FETCH statements with omitted direction, FROM/IN, or signed counts #3050

Backlog

Description

@icecrasher321

Reproduction

With sqlparser = "=0.64.0":

use sqlparser::{dialect::PostgreSqlDialect, parser::Parser};

fn main() {
    for sql in [
        "FETCH c;",
        "FETCH 1 c;",
        "FETCH FORWARD FROM c;",
        "FETCH -1 FROM c;",
    ] {
        match Parser::parse_sql(&PostgreSqlDialect {}, sql) {
            Ok(statements) => println!("{sql} => {statements:?}"),
            Err(error) => println!("{sql} => {error}"),
        }
    }
}

Actual behavior

FETCH c; => sql parser error: Expected: a concrete value, found: c at Line: 1, Column: 7
FETCH 1 c; => sql parser error: Expected FROM or IN at Line: 1, Column: 9
FETCH FORWARD FROM c; => sql parser error: Expected: a concrete value, found: FROM at Line: 1, Column: 15
FETCH -1 FROM c; => sql parser error: Expected: a value, found: - at Line: 1, Column: 7

Expected behavior

All four statements parse as Statement::Fetch (treating an omitted direction as NEXT, allowing FROM/IN and FORWARD/BACKWARD counts to be omitted, and accepting signed counts).

PostgreSQL documentation for FETCH

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions