Skip to content

Postgres: support OVERRIDING { SYSTEM | USER } VALUE in INSERT #2624

Closed

Description

@zvonimir-dd

Summary

PostgreSQL's INSERT accepts OVERRIDING { SYSTEM | USER } VALUE between the column list and the source (it controls whether supplied values or the sequence are used for identity columns). sqlparser rejects it, in both the PostgreSQL and the generic dialect.

Reproduction (sqlparser 0.63.0)

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

let sql = "INSERT INTO t (id, a) OVERRIDING SYSTEM VALUE VALUES (1, 'x')";
Parser::parse_sql(&PostgreSqlDialect {}, sql).unwrap();
sql parser error: Expected: SELECT, VALUES, or a subquery in the query body, found: OVERRIDING at Line: 1, Column: 23

OVERRIDING USER VALUE fails the same way. Both statements run on PostgreSQL (checked on 16.15):

CREATE TABLE t (id int GENERATED ALWAYS AS IDENTITY, a text);
INSERT INTO t (id, a) OVERRIDING SYSTEM VALUE VALUES (1, 'x');
INSERT INTO t (id, a) OVERRIDING USER VALUE VALUES (1, 'x');

Grammar

From https://www.postgresql.org/docs/current/sql-insert.html:

INSERT INTO table_name [ AS alias ] [ ( column_name [, ...] ) ]
    [ OVERRIDING { SYSTEM | USER } VALUE ]
    { DEFAULT VALUES | VALUES ( { expression | DEFAULT } [, ...] ) [, ...] | query }
    [ ON CONFLICT [ conflict_target ] conflict_action ]
    [ RETURNING ... ]

Proposed change

A new OVERRIDING keyword and an optional field on Insert, for example

/// PostgreSQL `OVERRIDING { SYSTEM | USER } VALUE`
pub overriding: Option<InsertOverriding>, // enum InsertOverriding { System, User }

parsed right after the column list and printed in the same position, so the statement round-trips. I'm happy to send a PR.

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