Thread: Domains and Casting

Domains and Casting

From
"Rod Taylor"
Date:
In order to make domains spec compliant I've added the ability for the
executor to handle Constraint * types, which it applies appropriately.
coerce_type wraps domains with the appropriate Constraint Nodes as
required.  I've run into a rather simple problem however.

CREATE DOMAIN int4notnulldomain int4 NOT NULL;
SELECT cast(cast(NULL as int4) as int4notnulldomain);  -- constraint
applied properly

SELECT cast(NULL as int4notnulldomain); -- constraint missed.


This appears to be due to makeTypeCast() in gram.y which bypasses
creating a TypeCast node for simple A_Const.

Removing the top part of the if (always creating a TypeCast node)
causes some rather extensive failures in the regression tests,
specifically with 'int4'::regproc type constructs.

Any advice?
--
Rod



Re: Domains and Casting

From
Tom Lane
Date:
"Rod Taylor" <rbt@zort.ca> writes:
> This appears to be due to makeTypeCast() in gram.y which bypasses
> creating a TypeCast node for simple A_Const.

My immediate reaction is that you've probably put the testing of
domain constraints in the wrong place.  You didn't say exactly
what your implementation looked like though ...
        regards, tom lane


Re: Domains and Casting

From
"Rod Taylor"
Date:
Erm... I suppose I didn't really intend to bring up domains at all.
I'm just playing trying to figure out how things work (easiest by
breaking them I think).

I don't understand why the below patch has such an adverse affect on
the system.
Causes:
     (p2.pronargs != 3 OR p2.proretset OR p2.proargtypes[2] !=
'int4'::regtype);
! ERROR:  Invalid type name 'int4'

or
     (p2.oprkind != 'b' OR p2.oprresult != 'bool'::regtype OR
! ERROR:  Invalid type name 'bool'



Index: src/backend/parser/gram.y
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/parser/gram.y,v
retrieving revision 2.314
diff -c -r2.314 gram.y
*** src/backend/parser/gram.y 2002/05/12 20:10:04 2.314
--- src/backend/parser/gram.y 2002/06/19 00:54:44
***************
*** 6424,6442 ****   * (We don't want to collapse x::type1::type2 into just x::type2.)   * Otherwise, generate a
TypeCastnode.   */
 
!  if (IsA(arg, A_Const) &&
!   ((A_Const *) arg)->typename == NULL)
!  {
!   ((A_Const *) arg)->typename = typename;
!   return arg;
!  }
!  else
!  {   TypeCast *n = makeNode(TypeCast);   n->arg = arg;   n->typename = typename;   return (Node *) n;
!  } }
 static Node *
--- 6424,6442 ----   * (We don't want to collapse x::type1::type2 into just x::type2.)   * Otherwise, generate a
TypeCastnode.   */
 
! // if (IsA(arg, A_Const) &&
! //  ((A_Const *) arg)->typename == NULL)
! // {
! //  ((A_Const *) arg)->typename = typename;
! //  return arg;
! // }
! // else
! // {   TypeCast *n = makeNode(TypeCast);   n->arg = arg;   n->typename = typename;   return (Node *) n;
! // } }
 static Node *
--
Rod
----- Original Message -----
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "Rod Taylor" <rbt@zort.ca>
Cc: "Hackers List" <pgsql-hackers@postgresql.org>
Sent: Tuesday, June 18, 2002 10:58 AM
Subject: Re: [HACKERS] Domains and Casting


> "Rod Taylor" <rbt@zort.ca> writes:
> > This appears to be due to makeTypeCast() in gram.y which bypasses
> > creating a TypeCast node for simple A_Const.
>
> My immediate reaction is that you've probably put the testing of
> domain constraints in the wrong place.  You didn't say exactly
> what your implementation looked like though ...
>
> regards, tom lane
>