"Martin Pitt" <[EMAIL PROTECTED]> 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.",

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

                http://www.postgresql.org/about/donate

Reply via email to