pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fabio Furia Silva <ff-@uol.com.br>
To: pgsql-hackers@postgresql.org
To: pgsql-general@postgresql.org
To: pgsql-interfaces@postgresql.org
Subject: Persistent variables between cross-calls in C functions
Date: Tue, 25 Mar 2003 13:12:00 -0300
Message-ID: <b5pv6j$2isf$1@news.hub.org> (raw)

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




view thread (5+ messages)  latest in thread

Message-ID: <b5pv6j$2isf$1@news.hub.org>
Permalink:  ../b5pv6j$2isf$1@news.hub.org/
Also on:    postgresql.org/message-id/b5pv6j$2isf$1@news.hub.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: ff-@uol.com.br, pgsql-hackers@postgresql.org, pgsql-general@postgresql.org
  Subject: Re: Persistent variables between cross-calls in C functions
  In-Reply-To: <b5pv6j$2isf$1@news.hub.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox