473,473 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Can you use a stored procedure in a subquery in postgres?

10 New Member
Can you use a stored procedure in a subquery in postgres?
Dec 4 '07 #1
4 5242
rski
700 Recognized Expert Contributor
Can you use a stored procedure in a subquery in postgres?
You mean any any procedure?
Dec 4 '07 #2
Shree111
10 New Member
You mean any any procedure?

CREATE OR REPLACE FUNCTION testobjectfortotal()
RETURNS SETOF total_type1d AS $$

begin

select (select account_id from tbl_ecpaccount where ecpuser_key =a.ecpuser_key) as Account_id, a.id,
(select distinct ecppayer_type from tbl_ecppayer where ecppayer_id = a.ecpclaim_carrier_id limit 1) as Payer_type,
(select * from zzz) as Payertype,
count(a.ecpclaim_carrier_id),
(select * from xxx) as ecpsubmitted
from tbl_ecpclaim a group by ecpclaim_carrier_id, ecpuser_key having ecpclaim_carrier_id in
(select distinct ecpclaim_carrier_id from tbl_ecpclaim);

return total_type1d;


end;

$$ LANGUAGE 'plpgsql';

i have written procedure like this but its showing error as following.......



ERROR: RETURN cannot have a parameter in function returning set; use RETURN NEXT at or near "total_type1d"

here "total_type1d" is type which contains userdefined types....
Dec 5 '07 #3
rski
700 Recognized Expert Contributor
CREATE OR REPLACE FUNCTION testobjectfortotal()
RETURNS SETOF total_type1d AS $$

begin

select (select account_id from tbl_ecpaccount where ecpuser_key =a.ecpuser_key) as Account_id, a.id,
(select distinct ecppayer_type from tbl_ecppayer where ecppayer_id = a.ecpclaim_carrier_id limit 1) as Payer_type,
(select * from zzz) as Payertype,
count(a.ecpclaim_carrier_id),
(select * from xxx) as ecpsubmitted
from tbl_ecpclaim a group by ecpclaim_carrier_id, ecpuser_key having ecpclaim_carrier_id in
(select distinct ecpclaim_carrier_id from tbl_ecpclaim);

return total_type1d;


end;

$$ LANGUAGE 'plpgsql';

i have written procedure like this but its showing error as following.......



ERROR: RETURN cannot have a parameter in function returning set; use RETURN NEXT at or near "total_type1d"

here "total_type1d" is type which contains userdefined types....

What do you wanr to rerutn, the whoel query you wrote. If co you have to use loops iterating select query. And use 'return next'. See more on postgresql.org in plplgsql section
Dec 6 '07 #4
Shree111
10 New Member
What do you wanr to rerutn, the whoel query you wrote. If co you have to use loops iterating select query. And use 'return next'. See more on postgresql.org in plplgsql section

yeah...thanks...i have got the result.....
Dec 6 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jarrod Morrison | last post by:
Hi all Im relatively new to using stored procedures and im not sure if it is possible to do what I am trying to do so any help here is greatly appreciated. I am using the variable @MachineName...
12
by: serge | last post by:
I have an SP that is big, huge, 700-800 lines. I am not an expert but I need to figure out every possible way that I can improve the performance speed of this SP. In the next couple of weeks I...
4
by: John | last post by:
Hi everyone, I have a stored procedure which I use to query a table. The first part of the stored procedure uses a cursor to update a temp table whilst the second part of the query actually...
7
by: Andrew Mayo | last post by:
Here's a really weird one for any SQL Server gurus out there... We have observed (SQL Server 2000) scenarios where a stored procedure which (a) begins a transaction (b) inserts some rows into...
2
by: Greg Stark | last post by:
I find I often want to be able to do joins against views where the view are aggregates on a column that has an index. Ie, something like SELECT a.*, v.n FROM a JOIN (select a_id,count(*) as n...
3
by: Amy | last post by:
I'm having trouble getting some data into a datagrid. It works fine for the results of the first SELECT in the stored procedure, but not therafter. Here's the error I get: "A field or property...
0
by: ambikadevi | last post by:
What is the function to call the Postgres stored procedures function using ADODB? PrepareSP() function is used to call the Oracle Stored Procedure. For PHP application. Waiting for the response!
4
by: gmadhava | last post by:
Hi Everybody, I am trying to update a column Percentage in a table named Critical Doctors with the a column named PercentTime from tblPercent table, Where the column Doctor matches with any...
5
by: bbawa1 | last post by:
I have the following stroed procedue. But whebnnI execute it it gives me following errors. Could you please tell me what is wrong Msg 156, Level 15, State 1, Procedure usp_DateDiff, Line 43...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.