Re: [SQL] Static variable inside PL/pgSQL (or) native C function - Mailing list pgsql-sql

From Pavel Stehule
Subject Re: [SQL] Static variable inside PL/pgSQL (or) native C function
Date
Msg-id CAFj8pRBq7DvMQY1JiXKMfXLcUHLEbUHNYdCTzpx4R3-M=7gw5Q@mail.gmail.com
Whole thread Raw
In response to [SQL] Static variable inside PL/pgSQL (or) native C function  (athinivas <athinivas@gmail.com>)
List pgsql-sql
Hi

2017-09-29 15:46 GMT+02:00 athinivas <athinivas@gmail.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@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

pgsql-sql by date:

Previous
From: athinivas
Date:
Subject: [SQL] Static variable inside PL/pgSQL (or) native C function
Next
From: "David G. Johnston"
Date:
Subject: Re: [SQL] Static variable inside PL/pgSQL (or) native C function