You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "amaksimo (via GitHub)" <gi...@apache.org> on 2026/06/05 23:17:35 UTC
[PR] PostgreSQL: support INCLUDE on PRIMARY KEY / UNIQUE table constraints [datafusion-sqlparser-rs]
amaksimo opened a new pull request, #2366:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2366
## Summary
PostgreSQL accepts `INCLUDE (col, ...)` covering columns on `PRIMARY KEY` and `UNIQUE` table constraints, both inline on `CREATE TABLE` and via `ALTER TABLE ADD CONSTRAINT`, per the [`index_parameters`][docs] grammar:
```sql
CREATE TABLE t (
id INT,
payload TEXT,
CONSTRAINT t_pk PRIMARY KEY (id) INCLUDE (payload)
);
ALTER TABLE t ADD CONSTRAINT t_uk UNIQUE (email) INCLUDE (payload);
```
The parser previously rejected both forms (`Expected: end of statement, found: INCLUDE` / `Expected: ',' or ')' after column definition, found: INCLUDE`).
[docs]: https://www.postgresql.org/docs/current/sql-createtable.html
## Changes
- Add `include: Vec<Ident>` to `PrimaryKeyConstraint` and `UniqueConstraint`. Empty when omitted.
- `Display` emits the clause between the columns list and `index_options`, matching PG's `index_parameters` clause order: `INCLUDE` -> `WITH` -> `USING INDEX TABLESPACE`.
- `Spanned` includes the `include` columns in the union.
- New `parse_optional_include_columns` helper on `Parser`, consumed from both PK and UNIQUE arms of `parse_optional_table_constraint`. Mirrors the existing INCLUDE handling on `CREATE INDEX`.
- Column-level inline forms (`id INT PRIMARY KEY`) carry `include: vec![]` since INCLUDE is not legal there in PG.
## Tests
New `parse_constraint_include_columns` in `tests/sqlparser_postgres.rs` covering inline / ALTER, PK / UNIQUE, single / multi-column INCLUDE, INCLUDE composing with `DEFERRABLE`, and AST-shape verification of the parsed `include` field.
`cargo test --all-features`, `cargo fmt --all`, and `cargo clippy --all-targets --all-features -- -D warnings` all pass locally.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] PostgreSQL: support INCLUDE on PRIMARY KEY / UNIQUE table constraints [datafusion-sqlparser-rs]
Posted by "iffyio (via GitHub)" <gi...@apache.org>.
iffyio merged PR #2366:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2366
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org