Skip to content

PostgreSQL: Accept TABLE as a top-level query #3039

Open

Description

@lei-jia-xing

PostgreSqlDialect accepts (TABLE t); but rejects TABLE t; at the start of a statement. PostgreSQL documents TABLE t as shorthand for SELECT * FROM t.

Reproduction

With sqlparser = "=0.64.0":

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

fn main() {
    for sql in ["TABLE t;", "(TABLE t);"] {
        match Parser::parse_sql(&PostgreSqlDialect {}, sql) {
            Ok(_) => println!("{sql} => OK"),
            Err(error) => println!("{sql} => {error}"),
        }
    }
}

Actual behavior

TABLE t; => sql parser error: Expected: an SQL statement, found: TABLE at Line: 1, Column: 1
(TABLE t); => OK

Expected behavior

Parse TABLE t; as a single query statement without requiring parentheses.

PostgreSQL SELECT documentation

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