apache / apache/datafusion-sqlparser-rs
PostgreSQL: Support `PRIMARY KEY USING INDEX` syntax in `ALTER TABLE`
- Dominant language
- Rust
- Stars
- 3.5k
- Forks
- 772
- Avg merge
- 4d 9h
- Merged PRs (30d)
- 17
Description
The parser fails to parse the PostgreSQL-specific `PRIMARY KEY USING INDEX index_name` syntax in `ALTER TABLE` statements:
```sql
ALTER TABLE version_downloads
ADD CONSTRAINT version_downloads_pkey PRIMARY KEY USING INDEX version_downloads_unique;
```
```
Expected: a list of columns in parentheses, found: INDEX
```
## Expected behavior
This is valid PostgreSQL syntax per the [ALTER TABLE documentation](https://www.postgresql.org/docs/current/sql-altertable.html). The grammar allows:
```
ADD table_constraint_using_index
```
Where `table_constraint_using_index` can be:
```
[ CONSTRAINT constraint_name ]
{ UNIQUE | PRIMARY KEY } USING INDEX index_name
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
```
Note that `PRIMARY KEY USING INDEX index_name` is a distinct form that does **not** require a column list - it promotes an existing unique index to be the primary key constraint.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating the ALTER TABLE grammar and the handling of table constraints in the Rust SQL parser. Use the PostgreSQL example from this issue as a parsing input, then add coverage for PRIMARY KEY USING INDEX and confirm that the statement parses without requiring a column list.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, rust, sql
- Domain
- compilers, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100