Projecting attributes of function return values

From: "Hiroshi Inoue" <Inoue(at)tpf(dot)co(dot)jp>
To: "pgsql-hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Projecting attributes of function return values
Date: 1998-12-03 10:06:07
Message-ID: 001501be1ea4$8b7ac020$2801007e@cadzone.tpf.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all

I have a simple patch about the treatment of functions.
But it may be self-satisfied.
Please check my patch at the end of this posting.

Case 1. executor evaluates functions twice

create table a (elem int4);
create function ax2(int4) returns a as
'select $1*2;' language 'sql';
select elem(ax2(1));

the result is

elem
----
4
(1 row)

it's wrong ?
it must be the following ?

elem
----
2
(1 row)

Case 2.parser rejects functions

create function elemout(a) returns int4 as
'select $1.elem;' language 'sql';
select elemout(ax2(1));

ERROR: Function 'elemout' has bad return type 315169

this elog() is necessary ?
In my patch I removed it and the result is

elemout
-------
2
(1 row)

Thanks

Hiroshi Inoue
Inoue(at)tpf(dot)co(dot)jp

*** backend/parser/parse_func.c.orig Thu Dec 3 18:25:31 1998
--- backend/parser/parse_func.c Thu Dec 3 18:39:18 1998
***************
*** 1352,1358 ****
newexpr->typeOid = funcnode->functype;
newexpr->opType = FUNC_EXPR;
newexpr->oper = (Node *) funcnode;
! newexpr->args = lcons(first_arg, NIL);

return (Node *) newexpr;
}
--- 1352,1358 ----
newexpr->typeOid = funcnode->functype;
newexpr->opType = FUNC_EXPR;
newexpr->oper = (Node *) funcnode;
! newexpr->args = expr->args;

return (Node *) newexpr;
}
***************
*** 1359,1366 ****

}

- elog(ERROR, "Function '%s' has bad return type %d",
- funcname, argtype);
break;
}
case T_Param:
--- 1359,1364 ----

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Sferacarta Software 1998-12-03 12:22:45 gram.y
Previous Message aaron ross 1998-12-03 04:56:32 Problem w/ psql crashing