carl at carl-olsen.com
Wed Jun 15 00:20:14 EDT 2005
ERROR: set-valued function called in context that cannot accept a set
CONTEXT: PL/pgSQL function "sp_getstatelist" line 6 at return next
My table is "Accounts_StateCodes"
The fields are "Description","StateCode","Region"
The types are varchar(60),char(2),varchar(60)
CREATE TYPE StateCodes AS (
FOR r IN SELECT "Description","StateCode" FROM "Accounts_StateCodes"
RETURN NEXT r;
From: mono-list-bounces at lists.ximian.com
[mailto:mono-list-bounces at lists.ximian.com] On Behalf Of Chris Aitken
Sent: Tuesday, June 07, 2005 9:24 AM
To: carl at carl-olsen.com; mono-list at lists.ximian.com
Subject: RE: [Mono-list] Npgsql.dll
> 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.
Mono-list maillist - Mono-list at lists.ximian.com
More information about the Mono-list