pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David G. Johnston <david.g.johnston@gmail.com>
To: athinivas <athinivas@gmail.com>
Cc: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Subject: Re: Static variable inside PL/pgSQL (or) native C function
Date: Fri, 29 Sep 2017 07:04:15 -0700
Message-ID: <CAKFQuwbg1efML7CeSTrg8WZ_qOQfmVCYbVWdUXvmbWAsjnmADw@mail.gmail.com> (raw)
In-Reply-To: <1506692779631-0.post@n3.nabble.com>
References: <1506692779631-0.post@n3.nabble.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

On Fri, Sep 29, 2017 at 6:46 AM, athinivas <athinivas@gmail.com> 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​

view thread (5+ messages)  latest in thread

Message-ID: <CAKFQuwbg1efML7CeSTrg8WZ_qOQfmVCYbVWdUXvmbWAsjnmADw@mail.gmail.com>
Permalink:  ../CAKFQuwbg1efML7CeSTrg8WZ_qOQfmVCYbVWdUXvmbWAsjnmADw@mail.gmail.com/
Also on:    postgresql.org/message-id/CAKFQuwbg1efML7CeSTrg8WZ_qOQfmVCYbVWdUXvmbWAsjnmADw@mail.gmail.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: david.g.johnston@gmail.com, athinivas@gmail.com
  Subject: Re: Static variable inside PL/pgSQL (or) native C function
  In-Reply-To: <CAKFQuwbg1efML7CeSTrg8WZ_qOQfmVCYbVWdUXvmbWAsjnmADw@mail.gmail.com>

* 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