Skip to content

Commit 1be17f1

Browse files
committed
>>You can alias $0, similar to the argument variables. And, I confirmed
>>that you cannot change the value, similar to the argument variables: > > Perhaps you shouldn't mark it isconst; then it would actually have some > usefulness (you could use it directly as a temporary variable to hold > the intended result). I can't see much value in aliasing it if it's > const, either. OK; the only change in this version is "isconst = false;". Now you can use $0 as a result placeholder if desired. E.g.: create or replace function tmp(anyelement, anyelement) returns anyarray as ' declare v_ret alias for $0; v_el1 alias for $1; v_el2 alias for $2; begin v_ret := ARRAY[v_el1, v_el2]; return v_ret; end; ' language 'plpgsql'; create table f(f1 text, f2 text, f3 int, f4 int); insert into f values ('a','b',1,2); insert into f values ('z','x',3,4); select tmp(f1,f2) from f; select tmp(f3,f4) from f; Joe Conway
1 parent 9df0306 commit 1be17f1

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/pl/plpgsql/src/pl_comp.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* procedural language
44
*
55
* IDENTIFICATION
6-
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.60 2003/07/25 23:37:28 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.61 2003/07/26 23:58:23 momjian Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -361,6 +361,42 @@ do_compile(FunctionCallInfo fcinfo,
361361
function->fn_rettyplen = typeStruct->typlen;
362362
function->fn_rettypelem = typeStruct->typelem;
363363
perm_fmgr_info(typeStruct->typinput, &(function->fn_retinput));
364+
365+
/*
366+
* install $0 reference, but only for polymorphic
367+
* return types
368+
*/
369+
if (procStruct->prorettype == ANYARRAYOID ||
370+
procStruct->prorettype == ANYELEMENTOID)
371+
{
372+
char buf[32];
373+
374+
/* name for variable */
375+
snprintf(buf, sizeof(buf), "$%d", 0);
376+
377+
/*
378+
* Normal return values get a var node
379+
*/
380+
var = malloc(sizeof(PLpgSQL_var));
381+
memset(var, 0, sizeof(PLpgSQL_var));
382+
383+
var->dtype = PLPGSQL_DTYPE_VAR;
384+
var->refname = strdup(buf);
385+
var->lineno = 0;
386+
var->datatype = build_datatype(typeTup, -1);
387+
var->isconst = false;
388+
var->notnull = false;
389+
var->default_val = NULL;
390+
391+
/* preset to NULL */
392+
var->value = 0;
393+
var->isnull = true;
394+
var->freeval = false;
395+
396+
plpgsql_adddatum((PLpgSQL_datum *) var);
397+
plpgsql_ns_additem(PLPGSQL_NSTYPE_VAR, var->varno,
398+
var->refname);
399+
}
364400
}
365401
ReleaseSysCache(typeTup);
366402

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy