Skip to content

Commit

Permalink
PostgreSQL: Support using DEFAULT for generated columns in INSERT (#3373
Browse files Browse the repository at this point in the history
)

* PostgreSQL: Support using DEFAULT for generated columns in INSERT AlecKazakova/sql-psi#287

* PostgreSQL: Use more predefined token

Co-authored-by: hfhbd <hfhbd@users.noreply.github.com>
  • Loading branch information
hfhbd and hfhbd committed Jul 15, 2022
1 parent dfacc9d commit 79816ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Expand Up @@ -9,17 +9,21 @@

parserImports=[
"static com.alecstrong.sql.psi.core.psi.SqlTypes.ABORT"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.ALWAYS"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.AS"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.ASC"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.BY"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.COLLATE"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.CONFLICT"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.CONSTRAINT"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.DELETE"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.DEFAULT"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.DESC"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.DO"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.DROP"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.FAIL"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.FROM"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.GENERATED"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.ID"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.STRING"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.IGNORE"
Expand Down Expand Up @@ -97,15 +101,15 @@ type_name ::= (
implements = "com.alecstrong.sql.psi.core.psi.SqlTypeName"
override = true
}
bind_parameter ::= ( '?' | ':' {identifier} ) {
bind_parameter ::= ( DEFAULT | '?' | ':' {identifier} ) {
extends = "com.alecstrong.sql.psi.core.psi.impl.SqlBindParameterImpl"
implements = "com.alecstrong.sql.psi.core.psi.SqlBindParameter"
override = true
}

identity_clause ::= 'IDENTITY'

generated_clause ::= 'GENERATED' ( ('ALWAYS' 'AS' <<expr '-1'>> 'STORED') | ( ('ALWAYS' | 'BY' 'DEFAULT') 'AS' identity_clause ) ) {
generated_clause ::= GENERATED ( (ALWAYS AS <<expr '-1'>> 'STORED') | ( (ALWAYS | BY DEFAULT) AS identity_clause ) ) {
extends = "com.alecstrong.sql.psi.core.psi.impl.SqlGeneratedClauseImpl"
implements = "com.alecstrong.sql.psi.core.psi.SqlGeneratedClause"
override = true
Expand All @@ -126,7 +130,7 @@ string_data_type ::= ((( 'CHARACTER' 'VARYING' ) | 'VARCHAR' | 'CHARACTER' | 'CH

uuid_data_type ::= 'UUID'

date_data_type ::= 'DATE' | (('TIME' | 'TIMESTAMP') [ '(' {signed_number} ')' ] [('WITH' | 'WITHOUT') 'TIME' 'ZONE']) | 'TIMESTAMPTZ' | 'INTERVAL'
date_data_type ::= 'DATE' | (('TIME' | 'TIMESTAMP') [ '(' {signed_number} ')' ] [(WITH | 'WITHOUT') 'TIME' 'ZONE']) | 'TIMESTAMPTZ' | 'INTERVAL'

boolean_data_type ::= 'BOOLEAN' | 'BOOL'

Expand Down Expand Up @@ -218,12 +222,12 @@ alter_table_column_alias ::= id | string {
]
}

alter_table_drop_column ::= 'DROP' [ COLUMN ] {column_name} {
alter_table_drop_column ::= DROP [ COLUMN ] {column_name} {
mixin = "app.cash.sqldelight.dialects.postgresql.grammar.mixins.AlterTableDropColumnMixin"
pin = 1
}

compound_select_stmt ::= [ {with_clause} ] {select_stmt} ( {compound_operator} {select_stmt} ) * [ 'ORDER' 'BY' {ordering_term} ( ',' {ordering_term} ) * ] [ 'LIMIT' {limiting_term} ] [ ( 'OFFSET' | ',' ) {limiting_term} ] [ 'FOR' 'UPDATE' [ 'SKIP' 'LOCKED' ] ] {
compound_select_stmt ::= [ {with_clause} ] {select_stmt} ( {compound_operator} {select_stmt} ) * [ ORDER BY {ordering_term} ( ',' {ordering_term} ) * ] [ LIMIT {limiting_term} ] [ ( OFFSET | ',' ) {limiting_term} ] [ 'FOR' UPDATE [ 'SKIP' 'LOCKED' ] ] {
extends = "com.alecstrong.sql.psi.core.psi.impl.SqlCompoundSelectStmtImpl"
implements = "com.alecstrong.sql.psi.core.psi.SqlCompoundSelectStmt"
override = true
Expand All @@ -250,7 +254,7 @@ extension_stmt ::= copy_stdin {
override = true
}

copy_stdin ::= 'COPY' [ {database_name} '.' ] {table_name} [ AS {table_alias} ] [ '(' {column_name} ( ',' {column_name} ) * ')' ] FROM 'STDIN' [ [ 'WITH' ] '(' copy_option ( ',' copy_option) * ')' ] [ WHERE <<expr '-1'>> ] {
copy_stdin ::= 'COPY' [ {database_name} '.' ] {table_name} [ AS {table_alias} ] [ '(' {column_name} ( ',' {column_name} ) * ')' ] FROM 'STDIN' [ [ WITH ] '(' copy_option ( ',' copy_option) * ')' ] [ WHERE <<expr '-1'>> ] {
mixin = "app.cash.sqldelight.dialects.postgresql.grammar.mixins.CopyMixin"
}

Expand Down
Expand Up @@ -19,5 +19,5 @@ CREATE TABLE test2(
words TEXT NOT NULL
);

INSERT INTO test2(words)
VALUES ('foo');
INSERT INTO test2(id, words)
VALUES (DEFAULT, 'foo');

0 comments on commit 79816ec

Please sign in to comment.