Persistent variables between cross-calls in C functions - Mailing list pgsql-general

From Fabio Furia Silva
Subject Persistent variables between cross-calls in C functions
Date
Msg-id b5pv6j$2isf$1@news.hub.org
Whole thread Raw
Responses Re: Persistent variables between cross-calls in C functions  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
List pgsql-general
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


pgsql-general by date:

Previous
From: Laszlo Hornyak
Date:
Subject: Re: PL/Java
Next
From: Alain Reymond
Date:
Subject: Re: Migrate Mysql to Posgresql