473,395 Members | 1,783 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,395 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 845

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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
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...

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.