Re: Writing SRF

From: Jorge Arevalo <jorgearevalo(at)gis4free(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL - General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Writing SRF
Date: 2010-04-28 20:20:14
Message-ID: h2pd321138e1004281320pe48cc85blb17467bb6308444e@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Apr 28, 2010 at 7:00 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Jorge Arevalo <jorgearevalo(at)gis4free(dot)org> writes:
>> I'm writing a SRF following the example from
>> http://www.postgresql.org/docs/8.4/interactive/xfunc-c.html (section
>> 34.9.10). In the example, in the code executed in first call, we get
>> the number of tuples to be returned, and no more. Then, in each call,
>> a new tuple is allocated and returned, until reach max_calls.
>
> You don't have to do it that way, by any means.  max_calls is just
> a field you can use if you feel like it --- it's not going to be
> looked at by anything outside your SRF.  If you don't want to determine
> the number of result rows at the start, just ignore max_calls, and
> use whatever method is convenient to decide that you're done
> returning rows.
>
>                        regards, tom lane
>

Yes, actually, I'm not using max_calls. I have my own stop condition.
Basically, I check if myStructsArray + call_cntr == NULL. I don't know
if it's the best way. I'll test it.

My doubt is if I'm doing things right getting all the stuff I need (an
array) in the first call, pointing user_fctx to this array and
accessing myStructsArray[call_cntr] in each successive call, until
myStructsArray + call_cntr == NULL (last array element?). In the
example, the row returned is generated from scratch in each call.

Many thanks,
Jorge

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2010-04-28 20:33:27 Re: Populate arrays from multiple rows
Previous Message Scott Marlowe 2010-04-28 19:29:43 Re: How many threads/cores Postgres can utilise?