mirror of
https://github.com/postgres/postgres.git
synced 2025-12-18 05:01:01 +03:00
Reimplement parsing and storage of default expressions and constraint
expressions in CREATE TABLE. There is no longer an emasculated expression syntax for these things; it's full a_expr for constraints, and b_expr for defaults (unfortunately the fact that NOT NULL is a part of the column constraint syntax causes a shift/reduce conflict if you try a_expr. Oh well --- at least parenthesized boolean expressions work now). Also, stored expression for a column default is not pre-coerced to the column type; we rely on transformInsertStatement to do that when the default is actually used. This means "f1 datetime default 'now'" behaves the way people usually expect it to. BTW, all the support code is now there to implement ALTER TABLE ADD CONSTRAINT and ALTER TABLE ADD COLUMN with a default value. I didn't actually teach ALTER TABLE to call it, but it wouldn't be much work.
This commit is contained in:
@@ -34,12 +34,17 @@ INSERT INTO DEFAULTEXPR_TBL (i2) VALUES (NULL);
|
||||
|
||||
SELECT '' AS four, * FROM DEFAULTEXPR_TBL;
|
||||
|
||||
-- errors
|
||||
-- test for:
|
||||
-- extraneous comma
|
||||
-- booleans not allowed
|
||||
-- syntax errors
|
||||
-- test for extraneous comma
|
||||
CREATE TABLE error_tbl (i int DEFAULT (100, ));
|
||||
-- this will fail because gram.y uses b_expr not a_expr for defaults,
|
||||
-- to avoid a shift/reduce conflict that arises from NOT NULL being
|
||||
-- part of the column definition syntax:
|
||||
CREATE TABLE error_tbl (b1 bool DEFAULT 1 < 2);
|
||||
-- this should work, however:
|
||||
CREATE TABLE error_tbl (b1 bool DEFAULT (1 < 2));
|
||||
|
||||
DROP TABLE error_tbl;
|
||||
|
||||
--
|
||||
-- CHECK syntax
|
||||
|
||||
@@ -34,7 +34,9 @@ four| i1|i2
|
||||
QUERY: CREATE TABLE error_tbl (i int DEFAULT (100, ));
|
||||
ERROR: parser: parse error at or near ","
|
||||
QUERY: CREATE TABLE error_tbl (b1 bool DEFAULT 1 < 2);
|
||||
ERROR: boolean expressions not supported in DEFAULT
|
||||
ERROR: parser: parse error at or near "<"
|
||||
QUERY: CREATE TABLE error_tbl (b1 bool DEFAULT (1 < 2));
|
||||
QUERY: DROP TABLE error_tbl;
|
||||
QUERY: CREATE TABLE CHECK_TBL (x int,
|
||||
CONSTRAINT CHECK_CON CHECK (x > 3));
|
||||
QUERY: INSERT INTO CHECK_TBL VALUES (5);
|
||||
|
||||
Reference in New Issue
Block a user