Re: Passing row set into PL/pgSQL function.

From: Craig Ringer <ringerc(at)ringerc(dot)id(dot)au>
To: Lucas Clemente Vella <lvella(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Passing row set into PL/pgSQL function.
Date: 2012-09-20 12:44:50
Message-ID: 505B0FC2.8080302@ringerc.id.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 09/20/2012 01:47 PM, Lucas Clemente Vella wrote:
>> http://www.depesz.com/2012/06/10/why-is-upsert-so-complicated/
>
> I have already seen this page, I am OK in running SERIALIZABLE
> transactions, and have no problem in replaying failed transactions due
> to race condition. Anyway, that is completely off my issue: I need
> upsert and I am prepared to deal with it. I just want to save typing
> by creating a reusable function.

In that case, maybe you could have your function accept a `refcursor`?

DECLARE some_curs CURSOR FOR VALUES ('a',1), ('b',2), ('c',3);
SELECT funky_upsert('table', ARRAY['col1','col2'], 'some_curs');
CLOSE some_curs;

Internally it could fetch rows from the refcursor into record fields and
do what it needed.

Personally I'd just do the work app-side.

--
Craig Ringer

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Johnston 2012-09-20 12:45:11 Re: RFE: Column aliases in WHERE clauses
Previous Message Martin French 2012-09-20 12:40:58 Re: Need psql send email