chris at ion-dreams.com
Tue Jun 7 10:23:44 EDT 2005
> It's me again, back to try and write some SPROC. I want to
> try the second method (PL/PgSQL), but I'm assuming you get
> back two arrays each with the same index, one for the
> customername and one for the postcode. Is that how you
> capture the returned data in a dataset?
If you set up as per the original example. It will return a set - i.e. a
table, much the same as a pure SQL query. My example here returns (within
Row customername(varchar) postcode(varchar)
1 data data
2 data data
N data data
Obviously the above is substituted for the actual data (apart from row
numbers). As I mentioned, is is returning a set of 'type', where in this
case the 'type' is called 'tp_company' is 2 columns of varchar, one named
customername, the other postcode. The type must be defined first:
CREATE TYPE tp_company AS
Now the actual SPROC is written:
CREATE FUNCTION plpgsql_company()
RETURNS SETOF tp_company AS
FOR r IN SELECT customername,postcode FROM
RETURN NEXT r;
LANGUAGE 'plpgsql' VOLATILE;
As can be seen, the function is defined as returning a set of 'tp_company'.
We then delare 'r' as being a row of 'tp_company'.
Then for each 'r' (row of 'tp_company', remember) in the SQL query, return
it, then loop until the end.
Return the whole shebang.
Hope this helps.
If you want me to write you an example for your data, let me know which
columns you want, table names & column types.
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
More information about the Mono-list