Re: Maintaining state across function calls

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: matt(at)byrney(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Maintaining state across function calls
Date: 2012-11-19 15:28:45
Message-ID: 1794.1353338925@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

matt(at)byrney(dot)com writes:
> The question is: what's the "best practice" way of letting a
> C/C++-language function hang onto internal state across calls?

A static variable for that is a really horrid idea. Instead use
fcinfo->flinfo->fn_extra to point to some workspace palloc'd in the
appropriate context. If you grep the PG sources for fn_extra you'll
find plenty of examples.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2012-11-19 15:30:46 Re: Prepared Statement Name Truncation
Previous Message Benedikt Grundmann 2012-11-19 15:27:14 Re: How to upgrade postgres 8.4 -> 9.1 contrib?