Persistent variables between cross-calls in C functions

From: "Fabio Furia Silva" <ff-(at)uol(dot)com(dot)br>
To: pgsql-hackers(at)postgresql(dot)org, pgsql-general(at)postgresql(dot)org, pgsql-interfaces(at)postgresql(dot)org
Subject: Persistent variables between cross-calls in C functions
Date: 2003-03-25 16:12:00
Message-ID: b5pv6j$2isf$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers pgsql-interfaces

Dear all:

I could not find any way to store a value in a C function between calls
inside the same session.

For example, the following function doesn't work as expected:

/********************************/
#include "postgres.h"
#include "fmgr.h"

PG_FUNCTION_INFO_V1(next_value);

Datum next_value(PG_FUNCTION_ARGS)
{
static int n;
PG_RETURN_INT32(n);
n++;
}

/********************************/
create function next_value()
returns integer as
'next.so' language C;

/********************************/
Calling

select next_value();

will always return 0,
even if I declare 'n' as a global variable outside the C function.

Thanks a lot.

Fabio Furia Silva

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Shridhar Daithankar<shridhar_daithankar@nospam.persistent.co.in> 2003-03-25 16:16:27 Re: trigger question.
Previous Message scott.marlowe 2003-03-25 16:03:39 Re: '' <> NULL

Browse pgsql-hackers by date

  From Date Subject
Next Message Josh Berkus 2003-03-25 17:28:09 Re: to_char(interval) --- done?
Previous Message Mike Meyer 2003-03-25 16:04:17 Re: Threaded Python vs. PostGreSQL plpython

Browse pgsql-interfaces by date

  From Date Subject
Next Message Stephan Szabo 2003-03-25 17:51:54 Re: Persistent variables between cross-calls in C functions
Previous Message William West 2003-03-25 15:19:33 Re: Interaction between Cursor and Transaction storage?