agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: athinivas <athinivas@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: Static variable inside PL/pgSQL (or) native C function
Date: Tue, 3 Oct 2017 10:15:03 -0700 (MST)
Message-ID: <1507050903928-0.post@n3.nabble.com> (raw)
In-Reply-To: <CAKFQuwbg1efML7CeSTrg8WZ_qOQfmVCYbVWdUXvmbWAsjnmADw@mail.gmail.com>
References: <1506692779631-0.post@n3.nabble.com>
	<CAKFQuwbg1efML7CeSTrg8WZ_qOQfmVCYbVWdUXvmbWAsjnmADw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

David G Johnston wrote
> On Fri, Sep 29, 2017 at 6:46 AM, athinivas &lt;

> athinivas@

> &gt; wrote:
> 
>> 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.
> 
> Why not just use a table and SQL locking features?
> 
> Dave​

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, 
Athi



--
Sent from: http://www.postgresql-archive.org/PostgreSQL-sql-f2142323.html


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



view thread (5+ messages)  latest in thread

Message-ID: <1507050903928-0.post@n3.nabble.com>
Permalink:  ../1507050903928-0.post@n3.nabble.com/
Also on:    postgresql.org/message-id/1507050903928-0.post@n3.nabble.com

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-sql@postgresql.org
  Cc: athinivas@gmail.com
  Subject: Re: Static variable inside PL/pgSQL (or) native C function
  In-Reply-To: <1507050903928-0.post@n3.nabble.com>

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

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