X-Original-To: pgsql-general@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 89562476285; Tue, 25 Mar 2003 11:13:08 -0500 (EST) Received: from news.hub.org (news.hub.org [64.49.215.80]) by postgresql.org (Postfix) with ESMTP id 0238B475A71; Tue, 25 Mar 2003 11:13:08 -0500 (EST) Received: by news.hub.org (Postfix, from userid 8) id D3BA943A611; Tue, 25 Mar 2003 11:13:07 -0500 (EST) From: "Fabio Furia Silva" X-Newsgroups: comp.databases.postgresql.interfaces, comp.databases.postgresql.hackers, comp.databases.postgresql.questions Subject: Persistent variables between cross-calls in C functions Date: Tue, 25 Mar 2003 13:12:00 -0300 Organization: Hub.Org Networking Services (http://www.hub.org) Lines: 40 Message-ID: X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 To: pgsql-hackers@postgresql.org, pgsql-general@postgresql.org, pgsql-interfaces@postgresql.org X-Spam-Status: No, hits=-5.2 required=5.0 tests=BAYES_10,PRIORITY_NO_NAME version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200303/1296 X-Sequence-Number: 39787 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