Skip site navigation (1) Skip section navigation (2)

Re: BUG #2971: 8.1.7/8.2.2 break constraint checking for 'update'

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Martin Pitt" <martin(at)piware(dot)de>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #2971: 8.1.7/8.2.2 break constraint checking for 'update'
Date: 2007-02-06 16:25:59
Message-ID: 12886.1170779159@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-bugs
"Martin Pitt" <martin(at)piware(dot)de> writes:
> db> create table foo (bar VARCHAR(20) NOT NULL check (bar in
> ('FOO','BAR')));
> CREATE TABLE

> db> insert into foo (bar) values ('FOO');
> INSERT 0 1

> db> update foo set bar = 'BAR';
> ERROR: attribute 1 has wrong type
> DETAIL: Table has type character varying, but query expects character varying.

Sigh.  The trouble with security patches is that by nature they can't
get very wide testing :-(.  I think we shall have to do something like
the attached.  Arguably this problem is exposing bugs elsewhere in the
system, but for now ExecEvalVar() is going to have to be less
aggressive.

			regards, tom lane

Index: execQual.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/executor/execQual.c,v
retrieving revision 1.212
diff -c -r1.212 execQual.c
*** execQual.c	3 Feb 2007 14:06:53 -0000	1.212
--- execQual.c	6 Feb 2007 16:14:08 -0000
***************
*** 488,495 ****
  		 * Note: we allow a reference to a dropped attribute.  slot_getattr
  		 * will force a NULL result in such cases.
  		 *
! 		 * Note: we check typmod, but allow the case that the Var has
! 		 * unspecified typmod while the column has a specific typmod.
  		 */
  		if (attnum > 0)
  		{
--- 488,498 ----
  		 * Note: we allow a reference to a dropped attribute.  slot_getattr
  		 * will force a NULL result in such cases.
  		 *
! 		 * Note: ideally we'd check typmod as well as typid, but that seems
! 		 * impractical at the moment: in many cases the tupdesc will have
! 		 * been generated by ExecTypeFromTL(), and that can't guarantee to
! 		 * generate an accurate typmod in all cases, because some expression
! 		 * node types don't carry typmod.
  		 */
  		if (attnum > 0)
  		{
***************
*** 505,513 ****
  			/* can't check type if dropped, since atttypid is probably 0 */
  			if (!attr->attisdropped)
  			{
! 				if (variable->vartype != attr->atttypid ||
! 					(variable->vartypmod != attr->atttypmod &&
! 					 variable->vartypmod != -1))
  					ereport(ERROR,
  							(errmsg("attribute %d has wrong type", attnum),
  							 errdetail("Table has type %s, but query expects %s.",
--- 508,514 ----
  			/* can't check type if dropped, since atttypid is probably 0 */
  			if (!attr->attisdropped)
  			{
! 				if (variable->vartype != attr->atttypid)
  					ereport(ERROR,
  							(errmsg("attribute %d has wrong type", attnum),
  							 errdetail("Table has type %s, but query expects %s.",

In response to

Responses

pgsql-bugs by date

Next:From: Tom LaneDate: 2007-02-06 16:36:49
Subject: Re: Strange "Table has type character varying, but query expects character varying" errors
Previous:From: Ümit ÖztosunDate: 2007-02-06 15:57:24
Subject: Strange "Table has type character varying, but query expects character varying" errors

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group