Re: Static variable inside PL/pgSQL (or) native C function

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: athinivas <athinivas(at)gmail(dot)com>
Cc: postgres list <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Static variable inside PL/pgSQL (or) native C function
Date: 2017-09-29 14:03:39
Message-ID: CAFj8pRBq7DvMQY1JiXKMfXLcUHLEbUHNYdCTzpx4R3-M=7gw5Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi

2017-09-29 15:46 GMT+02:00 athinivas <athinivas(at)gmail(dot)com>:

> 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.
>

no, there are no similar feature. More it should not work as you are
expecting, because PostgreSQL is process based, not thread based.

For this purpose, you can write some simple extension designed over shared
memory.

Regards

Pavel

>
> Thanks,
> Athi
>
>
>
> --
> Sent from: http://www.postgresql-archive.org/PostgreSQL-sql-f2142323.html
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message David G. Johnston 2017-09-29 14:04:15 Re: Static variable inside PL/pgSQL (or) native C function
Previous Message athinivas 2017-09-29 13:46:19 Static variable inside PL/pgSQL (or) native C function