Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1be17f1

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 canuse $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 parent9df0306 commit1be17f1

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+
charbuf[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)

[8]ページ先頭

©2009-2025 Movatter.jp