Thread: passing a record as a function argument in pl/pgsql

passing a record as a function argument in pl/pgsql

From
"Alon Noy"
Date:
<div class="Section1"><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt;
font-family:Arial">Is it possible?</span></font><p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size:10.0pt;
font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt;
font-family:Arial">From what I tried it is possible to create such a function but it is not possible to call <span
class="GramE">it?!</span></span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; 
font-family:Arial">Can anyone provide an example?</span></font><p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size:10.0pt;
font-family:Arial"> </span></font><p class="MsoNormal"><span class="SpellE"><span class="GramE"><font face="Arial"
size="2"><spanstyle="font-size:10.0pt;font-family:Arial">Tnx</span></font></span></span><span class="GramE"><font
face="Arial"size="2"><span style="font-size:10.0pt;font-family: 
Arial">.</span></font></span><font face="Arial" size="2"><span style="font-size:
10.0pt;font-family:Arial"></span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt;
font-family:Arial"> </span></font></div>

Re: passing a record as a function argument in pl/pgsql

From
Joe Conway
Date:
Alon Noy wrote:
> From what I tried it is possible to create such a function but it is not
> possible to call it ?!
> Can anyone provide an example?

create table foo (f1 int, f2 text);

insert into foo values(1,'a');
insert into foo values(2,'b');
insert into foo values(3,'c');

create or replace function get_foo(int) returns foo as 'select * from 
foo where f1 = $1' language 'sql';

create or replace function use_foo(foo) returns text as '
declare v_foo alias for $1;
begin  return v_foo.f2;
end;
' language 'plpgsql';

regression=# select use_foo(get_foo(2)); use_foo
--------- b
(1 row)

HTH,

Joe