Commit a4a232b1 authored by Peter Eisentraut's avatar Peter Eisentraut

Error position support for defaults and check constraints

Add support for error position reporting for the expressions contained
in defaults and check constraint definitions.  This currently works only
for CREATE TABLE, not ALTER TABLE, because the latter is not set up to
pass around the original query string.
Reviewed-by: default avatarFabien COELHO <coelho@cri.ensmp.fr>
parent 4b035841
......@@ -2460,7 +2460,8 @@ AddRelationNewConstraints(Relation rel,
List *newConstraints,
bool allow_merge,
bool is_local,
bool is_internal)
bool is_internal,
const char *queryString)
{
List *cookedConstraints = NIL;
TupleDesc tupleDesc;
......@@ -2489,6 +2490,7 @@ AddRelationNewConstraints(Relation rel,
* rangetable entry. We need a ParseState for transformExpr.
*/
pstate = make_parsestate(NULL);
pstate->p_sourcetext = queryString;
rte = addRangeTableEntryForRelation(pstate,
rel,
NULL,
......
......@@ -985,7 +985,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
*/
if (rawDefaults || stmt->constraints)
AddRelationNewConstraints(rel, rawDefaults, stmt->constraints,
true, true, false);
true, true, false, queryString);
ObjectAddressSet(address, RelationRelationId, relationId);
......@@ -5587,7 +5587,7 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
* _list_ of defaults, but we just do one.
*/
AddRelationNewConstraints(rel, list_make1(rawEnt), NIL,
false, true, false);
false, true, false, NULL);
/* Make the additional catalog changes visible */
CommandCounterIncrement();
......@@ -6178,7 +6178,7 @@ ATExecColumnDefault(Relation rel, const char *colName,
* _list_ of defaults, but we just do one.
*/
AddRelationNewConstraints(rel, list_make1(rawEnt), NIL,
false, true, false);
false, true, false, NULL);
}
ObjectAddressSubSet(address, RelationRelationId,
......@@ -7215,7 +7215,8 @@ ATAddCheckConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
list_make1(copyObject(constr)),
recursing | is_readd, /* allow_merge */
!recursing, /* is_local */
is_readd); /* is_internal */
is_readd, /* is_internal */
NULL); /* queryString not available here */
/* we don't expect more than one constraint here */
Assert(list_length(newcons) <= 1);
......
......@@ -102,7 +102,8 @@ extern List *AddRelationNewConstraints(Relation rel,
List *newConstraints,
bool allow_merge,
bool is_local,
bool is_internal);
bool is_internal,
const char *queryString);
extern void RelationClearMissing(Relation rel);
extern void SetAttrMissing(Oid relid, char *attname, char *value);
......
......@@ -228,6 +228,8 @@ CREATE TABLE SYS_COL_CHECK_TBL (city text, state text, is_capital bool,
altitude int,
CHECK (NOT (is_capital AND ctid::text = 'sys_col_check_tbl')));
ERROR: system column "ctid" reference in check constraint is invalid
LINE 3: CHECK (NOT (is_capital AND ctid::text = 'sys_col_check...
^
--
-- Check inheritance of defaults and constraints
--
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment