Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzQnq-0006Ll-LQ for pgsql-sql@arkaria.postgresql.org; Tue, 03 Oct 2017 17:16:18 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dzQnq-0003tv-3T for pgsql-sql@arkaria.postgresql.org; Tue, 03 Oct 2017 17:16:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dzQmp-00024p-AQ for pgsql-sql@postgresql.org; Tue, 03 Oct 2017 17:15:15 +0000 Received: from n3.nabble.com ([162.255.23.22]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzQmf-0003JL-Dd for pgsql-sql@postgresql.org; Tue, 03 Oct 2017 17:15:14 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id E37BC8A9F92C for ; Tue, 3 Oct 2017 10:15:03 -0700 (MST) Date: Tue, 3 Oct 2017 10:15:03 -0700 (MST) From: athinivas To: pgsql-sql@postgresql.org Message-ID: <1507050903928-0.post@n3.nabble.com> In-Reply-To: References: <1506692779631-0.post@n3.nabble.com> Subject: Re: Static variable inside PL/pgSQL (or) native C function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org David G Johnston wrote > On Fri, Sep 29, 2017 at 6:46 AM, athinivas < > athinivas@ > > wrote: >=20 >> Hi, >> >> Is it possible to have static variable inside pgSQL C functions (or) >> PL/pgSQL?? I'm having a use case where I need to update a counter inside >> the >> function & it should be thread-safe. >> >> I've tried using static variable inside the C function along with >> pthread_mutex_lock/pthread_mutex_unlock. And found functions are not >> shared >> among each other. >> >> > Don't know what's possible in C; pretty sure no in pl/pgsql. >=20 > Why not just use a table and SQL locking features? >=20 > Dave=E2=80=8B Sadly, I'm doing it in slave server, so not able to use any table INSERT/UPDATE. Does current_Setting() can be used to access any global variables?? thanks,=20 Athi -- Sent from: http://www.postgresql-archive.org/PostgreSQL-sql-f2142323.html --=20 Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql