Passing arrays to stored procedures

From: William Garrison <postgres(at)mobydisk(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Passing arrays to stored procedures
Date: 2007-04-20 23:33:41
Message-ID: 46294DD5.40905@mobydisk.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a stored procedure that takes a list of IDs and uses the ANY
operator:

CREATE OR REPLACE FUNCTION CalculateTotals(
customerList bytea[],
out total bigint,
out most_recent_login_date date)
AS $$
BEGIN
SELECT
SUM(totalsize), MAX(last_login)
INTO
$2,$3
FROM
customer
WHERE
customerid = ANY($1);
END;
$$ LANGUAGE 'plpgsql' STABLE;

I'm using npgsql and C#, and I've realized it doesn't support passing
arrays. Barring things like updating npgsql, what form of hackiness
would work best here?

The customerIDs are GUIDs represented as 16-byte arrays. I can pass
them as encoded strings separated by commas or some such silliness. But
I don't see a nice clean split() function that returns me an array. :-(

I'm trying to find some way to pass a postgres array constructor syntax
and have that evaluated, like ARRAY['binary':bytea,...,...] or
{...,...,...} something like that.

Does anyone have any suggestions?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-04-21 00:21:09 Re: Passing arrays to stored procedures
Previous Message Jeff Davis 2007-04-20 23:10:38 Re: unique constraint on 2 columns