diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2019-04-01 10:46:37 +0200 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2019-04-01 10:46:37 +0200 |
commit | 7241911782a7420e38b6e50b57d304ea48bc5362 (patch) | |
tree | 687e642d5b3256ab24d35cb4d16f86002c6f1df9 /src/backend | |
parent | 4ae7f02b0364ccba49a82efbfff46125fb357d6c (diff) | |
download | postgresql-7241911782a7420e38b6e50b57d304ea48bc5362.tar.gz postgresql-7241911782a7420e38b6e50b57d304ea48bc5362.zip |
Catch syntax error in generated column definition
The syntax
GENERATED BY DEFAULT AS (expr)
is not allowed but we have to accept it in the grammar to avoid
shift/reduce conflicts because of the similar syntax for identity
columns. The existing code just ignored this, incorrectly. Add an
explicit error check and a bespoke error message.
Reported-by: Justin Pryzby <pryzby@telsasoft.com>
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/parser/gram.y | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 01521789e82..b51f12dc232 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -3505,6 +3505,19 @@ ColConstraintElem: n->raw_expr = $5; n->cooked_expr = NULL; n->location = @1; + + /* + * Can't do this in the grammar because of shift/reduce + * conflicts. (IDENTITY allows both ALWAYS and BY + * DEFAULT, but generated columns only allow ALWAYS.) We + * can also give a more useful error message and location. + */ + if ($2 != ATTRIBUTE_IDENTITY_ALWAYS) + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("for a generated column, GENERATED ALWAYS must be specified"), + parser_errposition(@2))); + $$ = (Node *)n; } | REFERENCES qualified_name opt_column_list key_match key_actions |