mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
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>
This commit is contained in:
@ -85,6 +85,11 @@ CREATE TABLE gtest_err_7d (a int PRIMARY KEY, b int GENERATED ALWAYS AS (generat
|
||||
ERROR: set-returning functions are not allowed in column generation expressions
|
||||
LINE 1: ...7d (a int PRIMARY KEY, b int GENERATED ALWAYS AS (generate_s...
|
||||
^
|
||||
-- GENERATED BY DEFAULT not allowed
|
||||
CREATE TABLE gtest_err_8 (a int PRIMARY KEY, b int GENERATED BY DEFAULT AS (a * 2) STORED);
|
||||
ERROR: for a generated column, GENERATED ALWAYS must be specified
|
||||
LINE 1: ...E gtest_err_8 (a int PRIMARY KEY, b int GENERATED BY DEFAULT...
|
||||
^
|
||||
INSERT INTO gtest1 VALUES (1);
|
||||
INSERT INTO gtest1 VALUES (2, DEFAULT);
|
||||
INSERT INTO gtest1 VALUES (3, 33); -- error
|
||||
|
@ -37,6 +37,9 @@ CREATE TABLE gtest_err_7b (a int PRIMARY KEY, b int GENERATED ALWAYS AS (row_num
|
||||
CREATE TABLE gtest_err_7c (a int PRIMARY KEY, b int GENERATED ALWAYS AS ((SELECT a)) STORED);
|
||||
CREATE TABLE gtest_err_7d (a int PRIMARY KEY, b int GENERATED ALWAYS AS (generate_series(1, a)) STORED);
|
||||
|
||||
-- GENERATED BY DEFAULT not allowed
|
||||
CREATE TABLE gtest_err_8 (a int PRIMARY KEY, b int GENERATED BY DEFAULT AS (a * 2) STORED);
|
||||
|
||||
INSERT INTO gtest1 VALUES (1);
|
||||
INSERT INTO gtest1 VALUES (2, DEFAULT);
|
||||
INSERT INTO gtest1 VALUES (3, 33); -- error
|
||||
|
Reference in New Issue
Block a user