On Wed, 31 Jan 2007, Tom Lane wrote:
Sergiy Vyshnevetskiy <[EMAIL PROTECTED]> writes:
Not at all. What's "broken" is the idea of variable as a simple piece of
memory. It is correct for base types, but not for domains - they may have
non-empty constructors (in C++ terminology).
That may be, but I'm unwilling to pay the overhead for *every* variable
when most of them won't be domains. I'm inclined to extend PLpgSQL_type
to include a domain indicator and only do it the hard way when we have to.
Why not add PLPGSQL_TTYPE_DOMAIN and rename PLPGSQL_TTYPE_SCALAR to
PLPGSQL_TTYPE_BASE? We only use PLPGSQL_TTYPE_SCALAR in _3_ places!
[ looks at code... ] Actually, I think we already have the flag we
need: look to see if the typinput function is strict.
All domains have domain_in as input function - it is NOT strict.
Anyway, as we assign a value to a domain variable we must check
constraints - that's the whole point of domains. Even when the value is
"null".
Hack attached. Any reasons not to call it a bugfix?
--- src/pl/plpgsql/src/pl_comp.c.orig Wed Oct 4 03:30:13 2006
+++ src/pl/plpgsql/src/pl_comp.c Thu Feb 1 14:59:07 2007
@@ -361,7 +361,8 @@
/* Disallow pseudotype argument */
/* (note we already replaced ANYARRAY/ANYELEMENT) */
/* (build_variable would do this, but wrong message) */
- if (argdtype->ttype != PLPGSQL_TTYPE_SCALAR &&
+ if (argdtype->ttype != PLPGSQL_TTYPE_BASE &&
+ argdtype->ttype != PLPGSQL_TTYPE_DOMAIN &&
argdtype->ttype != PLPGSQL_TTYPE_ROW)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
@@ -1455,7 +1456,8 @@
switch (dtype->ttype)
{
- case PLPGSQL_TTYPE_SCALAR:
+ case PLPGSQL_TTYPE_BASE:
+ case PLPGSQL_TTYPE_DOMAIN:
{
/* Ordinary scalar datatype */
PLpgSQL_var *var;
@@ -1744,8 +1746,10 @@
switch (typeStruct->typtype)
{
case 'b': /* base type */
+ typ->ttype = PLPGSQL_TTYPE_BASE;
+ break;
case 'd': /* domain */
- typ->ttype = PLPGSQL_TTYPE_SCALAR;
+ typ->ttype = PLPGSQL_TTYPE_DOMAIN;
break;
case 'c': /* composite, ie, rowtype */
Assert(OidIsValid(typeStruct->typrelid));
--- src/pl/plpgsql/src/pl_exec.c.orig Wed Oct 4 03:30:13 2006
+++ src/pl/plpgsql/src/pl_exec.c Thu Feb 1 15:04:17 2007
@@ -844,6 +844,11 @@
{
var->value = (Datum) 0;
var->isnull = true;
+ if(var->datatype->ttype!=PLPGSQL_TTYPE_BASE)
+ {
+ exec_assign_value(estate, (PLpgSQL_datum *) var,
+ 0, UNKNOWNOID, &(var->isnull));
+ }
if (var->notnull)
ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
--- src/pl/plpgsql/src/plpgsql.h.orig Wed Oct 4 03:30:14 2006
+++ src/pl/plpgsql/src/plpgsql.h Thu Feb 1 14:41:29 2007
@@ -61,7 +61,8 @@
*/
enum
{
- PLPGSQL_TTYPE_SCALAR, /* scalar types and domains */
+ PLPGSQL_TTYPE_BASE, /* scalar types and domains */
+ PLPGSQL_TTYPE_DOMAIN, /* scalar types and domains */
PLPGSQL_TTYPE_ROW, /* composite types */
PLPGSQL_TTYPE_REC, /* RECORD pseudotype */
PLPGSQL_TTYPE_PSEUDO /* other pseudotypes */
---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly