mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-31 00:03:57 -04:00 
			
		
		
		
	>>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
			
			
This commit is contained in:
		
							parent
							
								
									9df03060e9
								
							
						
					
					
						commit
						1be17f1f26
					
				| @ -3,7 +3,7 @@ | |||||||
|  *			  procedural language |  *			  procedural language | ||||||
|  * |  * | ||||||
|  * IDENTIFICATION |  * IDENTIFICATION | ||||||
|  *	  $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.60 2003/07/25 23:37:28 tgl Exp $ |  *	  $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.61 2003/07/26 23:58:23 momjian Exp $ | ||||||
|  * |  * | ||||||
|  *	  This software is copyrighted by Jan Wieck - Hamburg. |  *	  This software is copyrighted by Jan Wieck - Hamburg. | ||||||
|  * |  * | ||||||
| @ -361,6 +361,42 @@ do_compile(FunctionCallInfo fcinfo, | |||||||
| 				function->fn_rettyplen = typeStruct->typlen; | 				function->fn_rettyplen = typeStruct->typlen; | ||||||
| 				function->fn_rettypelem = typeStruct->typelem; | 				function->fn_rettypelem = typeStruct->typelem; | ||||||
| 				perm_fmgr_info(typeStruct->typinput, &(function->fn_retinput)); | 				perm_fmgr_info(typeStruct->typinput, &(function->fn_retinput)); | ||||||
|  | 
 | ||||||
|  | 				/*
 | ||||||
|  | 				 * install $0 reference, but only for polymorphic | ||||||
|  | 				 * return types | ||||||
|  | 				 */ | ||||||
|  | 				if (procStruct->prorettype == ANYARRAYOID || | ||||||
|  | 					procStruct->prorettype == ANYELEMENTOID) | ||||||
|  | 				{ | ||||||
|  | 					char		buf[32]; | ||||||
|  | 
 | ||||||
|  | 					/* name for variable */ | ||||||
|  | 					snprintf(buf, sizeof(buf), "$%d", 0); | ||||||
|  | 
 | ||||||
|  | 					/*
 | ||||||
|  | 					 * Normal return values get a var node | ||||||
|  | 					 */ | ||||||
|  | 					var = malloc(sizeof(PLpgSQL_var)); | ||||||
|  | 					memset(var, 0, sizeof(PLpgSQL_var)); | ||||||
|  | 
 | ||||||
|  | 					var->dtype = PLPGSQL_DTYPE_VAR; | ||||||
|  | 					var->refname = strdup(buf); | ||||||
|  | 					var->lineno = 0; | ||||||
|  | 					var->datatype = build_datatype(typeTup, -1); | ||||||
|  | 					var->isconst = false; | ||||||
|  | 					var->notnull = false; | ||||||
|  | 					var->default_val = NULL; | ||||||
|  | 
 | ||||||
|  | 					/* preset to NULL */ | ||||||
|  | 					var->value = 0; | ||||||
|  | 					var->isnull = true; | ||||||
|  | 					var->freeval = false; | ||||||
|  | 
 | ||||||
|  | 					plpgsql_adddatum((PLpgSQL_datum *) var); | ||||||
|  | 					plpgsql_ns_additem(PLPGSQL_NSTYPE_VAR, var->varno, | ||||||
|  | 									   var->refname); | ||||||
|  | 				} | ||||||
| 			} | 			} | ||||||
| 			ReleaseSysCache(typeTup); | 			ReleaseSysCache(typeTup); | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user