system_col_constr.patch

text/plain

Filename: system_col_constr.patch
Type: text/plain
Part: 0
Message: FW: Minor inheritance/check bug: Inconsistent behavior

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: context
File+
src/backend/executor/nodeModifyTable.c 8 0
src/backend/parser/parse_relation.c 12 0
*** a/src/backend/executor/nodeModifyTable.c
--- b/src/backend/executor/nodeModifyTable.c
***************
*** 226,231 **** ExecInsert(TupleTableSlot *slot,
--- 226,235 ----
  	}
  	else
  	{
+ 		/* Set the relation OID in tuple here only so that if OID is used as part of constraint check then 
+ 		 * it will be able to evaluate result of constraint correctly.*/
+ 		tuple->t_tableOid = RelationGetRelid(resultRelationDesc);
+ 	
  		/*
  		 * Check the constraints of the tuple
  		 */
***************
*** 540,545 **** ExecUpdate(ItemPointer tupleid,
--- 544,553 ----
  	}
  	else
  	{
+ 		/* Set the relation OID in tuple here only so that if OID is used as part of constraint check then 
+ 		 * it will be able to evaluate result of constraint correctly.*/	
+ 		tuple->t_tableOid = RelationGetRelid(resultRelationDesc);
+ 	
  		/*
  		 * Check the constraints of the tuple
  		 *
*** a/src/backend/parser/parse_relation.c
--- b/src/backend/parser/parse_relation.c
***************
*** 549,554 **** scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte, char *colname,
--- 549,566 ----
  	{
  		/* quick check to see if name could be a system column */
  		attnum = specialAttNum(colname);
+ 
+ 		/* In constraint check, no system column are allowed except tableoid*/
+               if ((pstate->p_expr_kind == EXPR_KIND_CHECK_CONSTRAINT)
+ 				&&(attnum < InvalidAttrNumber) 
+ 				&& (attnum !=  TableOidAttributeNumber))
+               {
+                     ereport(ERROR,
+                         (errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
+                         errmsg("system column \"%s\" reference in check constraint is invalid", colname),
+                         parser_errposition(pstate, location)));
+               }
+ 		
  		if (attnum != InvalidAttrNumber)
  		{
  			/* now check to see if column actually is defined */