Re: [ADMIN] How to cal function in in another function

From: "Chandra Sekhar Surapaneni" <chandu(at)positivenetworks(dot)net>
To: "VivekanandaSwamy R(dot)" <VivekanandaSwamyr(at)infics(dot)com>, <pgadmin-support(at)postgresql(dot)org>
Cc: <pgsql-admin-owner(at)postgresql(dot)org>
Subject: Re: [ADMIN] How to cal function in in another function
Date: 2006-07-03 20:01:21
Message-ID: 0F7F9A82BB0DBB4396A9F8386D0E0612011AE78A@pos-exch1.corp.positivenetworks.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgadmin-support

You should try it as follows:

create or replace function subfun1(int8) returns record as
'
declare
rec record;
begin
select ename as ename,mgr as mgr into rec from emp where empno=$1 ;
return rec;
end;
'
language'plpgsql';
---------------------------------------------------------

select subfun1(22);
subfun1
-------------
(swarna,23)

------------------------------------------------------------

create or replace function mainfun(int8) returns record as
'
declare
no record;
return_rec record;
begin
no := subfun1($1);
select sal,dept into return_rec from emp where mgr=no.mgr limit 1;
return return_rec;
end;
'
language'plpgsql';

-------------------------------------------------
select mainfun(22);
mainfun
-----------
(2600,20)
-------------------------------------------------


Regards,
Chandra Sekhar Surapaneni

________________________________

From: pgsql-admin-owner(at)postgresql(dot)org
[mailto:pgsql-admin-owner(at)postgresql(dot)org] On Behalf Of VivekanandaSwamy
R.
Sent: Wednesday, June 28, 2006 3:53 AM
To: pgadmin-support(at)postgresql(dot)org
Cc: pgsql-admin-owner(at)postgresql(dot)org
Subject: [ADMIN] How to cal function in in another function

Hi,
i have written these functions....,please go through this...

table emp: It contains

empno ename mgr sal dept
------------------------------------------------------------------------
-
22 swarna 23 2600 20

Now i wrote function(sub function)

create or replace function subfun1(int8,out p_mgr int8,out p_name
varchar) as
'
begin
select ename,mgr into p_name,p_mgr from emp where empno=$1 ;
end;
'
language'plpgsql';

When i executing this function,it returns like....
select subfun1(22); returns (23,swarna) as record type

Now i want use/call this function in main function

create or replace function mainfun(int8,out p_sal int8,out p_dept
varchar) as
'
declare
no record;
begin
select subfun1($1) into no;
select sal,dept into p_sal,p_dept from emp where mgr=no.p_mgr limit 1;
end;
'
language'plpgsql';

Now when i am executing this function like....

select mainfun(22); returns error message like....

ERROR: record "no" has no field "p_mgr"
CONTEXT: PL/pgSQL function "mainfun" line 5 at select into
variables

So,how to solve this problem?









Thanks & Regards

Vivekananda.R | Software Engineer

Infinite Computer Solutions | Exciting Times...Infinite Possibilities...

SEI-CMMI level 5 | ISO 9001:2000

Tel +91-80-5193-0000| Fax +91-80-51930009 | Cell No
+91-9986463365|www.infics.com


Information transmitted by this e-mail is proprietary to Infinite
Computer Solutions and / or its Customers and is intended for use only
by the individual or the entity to which it is addressed, and may
contain information that is privileged, confidential or exempt from
disclosure under applicable law. If you are not the intended recipient
or it appears that this mail has been forwarded to you without proper
authority, you are notified that any use or dissemination of this
information in any manner is strictly prohibited. In such cases, please
notify us immediately at info(dot)in(at)infics(dot)com and delete this email from
your records.

Browse pgadmin-support by date

  From Date Subject
Next Message Keith C. Perry 2006-07-03 20:46:19 Re: How to provide db access to other systems
Previous Message Dave Page 2006-07-03 18:49:31 Re: pgadmin3 segmentation fault