- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1k
 
feat(postgresql): add support for table creation DDL that contains a primary key alongside the INCLUDE keyword #5425
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -2997,9 +2997,11 @@ def foreignkey_sql(self, expression: exp.ForeignKey) -> str: | |
| 
     | 
||
| def primarykey_sql(self, expression: exp.ForeignKey) -> str: | ||
| expressions = self.expressions(expression, flat=True) | ||
| include = self.expressions(expression, key="include", flat=True) | ||
| include = f" INCLUDE ({include})" if include else "" | ||
| 
         
      Comment on lines
    
      +3000
     to 
      +3001
    
   
  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto, if we have an  include = self.sql(expression, "include")
include = f" {include}" if include else ""There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately here when I run this suggested code as is, I get the following error: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your version is the correct one– you need to use   | 
||
| options = self.expressions(expression, key="options", flat=True, sep=" ") | ||
| options = f" {options}" if options else "" | ||
| return f"PRIMARY KEY ({expressions}){options}" | ||
| return f"PRIMARY KEY ({expressions}){include}{options}" | ||
| 
     | 
||
| def if_sql(self, expression: exp.If) -> str: | ||
| return self.case_sql(exp.Case(ifs=[expression], default=expression.args.get("false"))) | ||
| 
          
            
          
           | 
    ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -6296,8 +6296,15 @@ def _parse_primary_key( | |
| expressions = self._parse_wrapped_csv( | ||
| self._parse_primary_key_part, optional=wrapped_optional | ||
| ) | ||
| 
     | 
||
| include = None | ||
| if self._match_text_seq("INCLUDE"): | ||
| include = self._parse_wrapped_id_vars() | ||
                
       | 
||
| 
     | 
||
| options = self._parse_key_constraint_options() | ||
| return self.expression(exp.PrimaryKey, expressions=expressions, options=options) | ||
| return self.expression( | ||
| exp.PrimaryKey, expressions=expressions, include=include, options=options | ||
| ) | ||
| 
     | 
||
| def _parse_bracket_key_value(self, is_map: bool = False) -> t.Optional[exp.Expression]: | ||
| return self._parse_slice(self._parse_alias(self._parse_assignment(), explicit=True)) | ||
| 
          
            
          
           | 
    ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -987,6 +987,7 @@ def test_ddl(self): | |
| self.validate_identity( | ||
| "CREATE TABLE t (vid INT NOT NULL, CONSTRAINT ht_vid_nid_fid_idx EXCLUDE (INT4RANGE(vid, nid) WITH &&, INT4RANGE(fid, fid, '[]') WITH &&))" | ||
| ) | ||
| self.validate_identity("CREATE TABLE t (i INT, a TEXT PRIMARY KEY (i) INCLUDE (a))") | ||
                
       | 
||
| self.validate_identity( | ||
| "CREATE TABLE t (i INT, PRIMARY KEY (i), EXCLUDE USING gist(col varchar_pattern_ops DESC NULLS LAST WITH &&) WITH (sp1=1, sp2=2))" | ||
| ) | ||
| 
          
            
          
           | 
    ||
Uh oh!
There was an error while loading. Please reload this page.