Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding EXCLUDE constraint support #3116

Merged
merged 7 commits into from
Mar 11, 2024
Merged

Conversation

VaggelisD
Copy link
Collaborator

@VaggelisD VaggelisD commented Mar 11, 2024

Fixes #3097

The syntax for the EXCLUDE table constraint is the following:

[CONSTRAINT constraint_name] EXCLUDE [ USING index_method ] ( exclude_element WITH operator [, ... ] ) index_parameters [ WHERE ( predicate ) ]

where:

<index_method> ::= identifier (see [1])
<exclude_element> ::= { column_name | ( expression ) } [ opclass ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ]
<opclass> ::= identifier (see [2])
<index_parameters> ::=  [ INCLUDE ( column_name [, ... ] ) ] 
                        [ WITH ( storage_parameter [= value] [, ... ] ) ]
                        [ USING INDEX TABLESPACE tablespace_name ]

Design Notes

  • Added exp.ExcludeElement that captures all information from exclude_element WITH operator [, ... ]
  • This is an exclusively Postgres feature afaik, but the changes are added on the base Dialect.

Docs

  1. Index methods
  2. Operator class
  3. EXCLUDE constraint

sqlglot/expressions.py Outdated Show resolved Hide resolved
sqlglot/parser.py Outdated Show resolved Hide resolved
sqlglot/parser.py Outdated Show resolved Hide resolved
sqlglot/parser.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@georgesittas georgesittas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, nice job! Can we get rid of that lstrip() call somehow?

sqlglot/generator.py Outdated Show resolved Hide resolved
@georgesittas georgesittas merged commit 09708f5 into main Mar 11, 2024
5 checks passed
@georgesittas georgesittas deleted the exclude_constraint branch March 11, 2024 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EXCLUDE indexes support for PostgreSQL dialect
3 participants