473,320 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Returning rowsets/results from a function to another one in plpgsl.

hi all,

I have a little strange scenario i need a function A
to call function B where in function B fetches a set
of records and returns the set to function A.

This is what i have going

CREATE OR REPLACE FUNCTION test(VARCHAR (40)) RETURNS
int AS
'
DECLARE
a_status_name ALIAS FOR $1;
count int;
arrStore text[];
BEGIN
count := 1;
SELECT INTO arrStore return_to_me(CAST (a_status_name
AS VARCHAR)) ;
WHILE arrStore[count] LOOP
RAISE NOTICE ''Print element %.'',arrStore[count];
count := count + 1;
END LOOP;
RETURN 1 ;
END
'
LANGUAGE 'plpgsql';
where return_to_me is as below:

CREATE OR REPLACE FUNCTION
return_to_me
(
VARCHAR(40)
)
RETURNS text[] AS
'
DECLARE
a_status_name ALIAS FOR $1;
order_rec record;
record_data text;
return_arr text[];
counter int;
BEGIN
counter := 1;
FOR order_rec in
SELECT ..
FROM ..
WHERE ..
LOOP
IF counter = 1 THEN
record_data = order_rec.ord_proc_state_guid;
ELSE
record_data = record_data || '','' || order_rec.field;
END IF;
counter := counter + 1;
END LOOP;

return_arr := ''{'' || record_data || ''}'';

RETURN return_arr;
END
'
LANGUAGE 'plpgsql';

versions of postgres below 7.4 ( i use 7.3.4) do not
support arrays as real arrays but as strings
{'a','b','bb'} and thats why i created the string as
above, the return_to_me function generates the psuedo
array correctly as {Sam,Miller,25} but when this needs
to be returned to the callee function test I get the
error

ERROR: syntax error at or near "[".

Am i doing something wrong (i guess so) If there is an
alternate way to achieve the same please do reply .
All help be greatly appreciated.

thanks
Sid

__________________________________________________ ______________________
Yahoo! India Matrimony: Find your partner online. http://yahoo.shaadi.com/india-matrimony/

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #1
0 949

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mountain Man | last post by:
Hi, I'm having trouble with the foreach function. I'm using it twice inside a user defined function with two different arrays, and in the second instance it's returning the value of the first...
7
by: Dr John Stockton | last post by:
What are the best ways of returning multiple results from a subroutine ? I've been using ... return } which is inelegant. I'm used to Pascal's procedure X(const A, B : integer; var C, D :...
41
by: Materialised | last post by:
I am writing a simple function to initialise 3 variables to pesudo random numbers. I have a function which is as follows int randomise( int x, int y, intz) { srand((unsigned)time(NULL)); x...
1
by: Guha | last post by:
I have a problem with returning a 2D array using a function which is called in main(). The piece of the code is given below. This is a test code only. #include"stdio.h" #include"alloc.h" ...
6
by: David Lozzi | last post by:
Here is the proc: CREATE PROCEDURE . @CID as int, @Netname as nvarchar(25), @Return as int OUTPUT AS IF EXISTS (SELECT DISTINCT netname FROM computers WHERE CompanyID = @CID AND...
0
by: Mr sidh bhatt | last post by:
hi all, I have a little strange scenario i need a function A to call function B where in function B fetches a set of records and returns the set to function A. This is what i have going ...
10
by: randomtalk | last post by:
hello, i have another problem i feel that i have to be missing something.. Basically, i've written a recursive function to find all the prime up to a number (lim).. here is the function: The...
6
by: InnoCreate | last post by:
Hi everyone. I've recently written a classic asp website which uses an MS Access datasource. I know this is less than an ideal data source as it has limited functionality. I have a search form on...
3
by: downwitch | last post by:
Hi, I'm having trouble getting data in ADO.Net recordsets. (VS 2005, SQL Server 2005). All my rowsets come back empty--whether sourced from queries or stored procs--despite ODBC connections with...
7
by: Thomas Lenz | last post by:
Please consider the following code snippet: string myfunction() { ostringstream oss; oss << "junk"; // do something more with oss; I can't make it const... return oss.str(); } Is the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.