agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
Static variable inside PL/pgSQL (or) native C function
5+ messages / 3 participants
[nested] [flat]

* Static variable inside PL/pgSQL (or) native C function
@ 2017-09-29 13:46 athinivas <athinivas@gmail.com>
  2017-09-29 14:03 ` Re: Static variable inside PL/pgSQL (or) native C function Pavel Stehule <pavel.stehule@gmail.com>
  2017-09-29 14:04 ` Re: Static variable inside PL/pgSQL (or) native C function David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 2 replies; 5+ messages in thread

From: athinivas @ 2017-09-29 13:46 UTC (permalink / raw)
  To: pgsql-sql

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. 

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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Static variable inside PL/pgSQL (or) native C function
  2017-09-29 13:46 Static variable inside PL/pgSQL (or) native C function athinivas <athinivas@gmail.com>
@ 2017-09-29 14:03 ` Pavel Stehule <pavel.stehule@gmail.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Pavel Stehule @ 2017-09-29 14:03 UTC (permalink / raw)
  To: athinivas <athinivas@gmail.com>; +Cc: 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
>

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Static variable inside PL/pgSQL (or) native C function
  2017-09-29 13:46 Static variable inside PL/pgSQL (or) native C function athinivas <athinivas@gmail.com>
@ 2017-09-29 14:04 ` David G. Johnston <david.g.johnston@gmail.com>
  2017-10-03 17:15   ` Re: Static variable inside PL/pgSQL (or) native C function athinivas <athinivas@gmail.com>
  1 sibling, 1 reply; 5+ messages in thread

From: David G. Johnston @ 2017-09-29 14:04 UTC (permalink / raw)
  To: athinivas <athinivas@gmail.com>; +Cc: pgsql-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​

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Static variable inside PL/pgSQL (or) native C function
  2017-09-29 13:46 Static variable inside PL/pgSQL (or) native C function athinivas <athinivas@gmail.com>
  2017-09-29 14:04 ` Re: Static variable inside PL/pgSQL (or) native C function David G. Johnston <david.g.johnston@gmail.com>
@ 2017-10-03 17:15   ` athinivas <athinivas@gmail.com>
  2017-10-03 17:25     ` Re: Static variable inside PL/pgSQL (or) native C function Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: athinivas @ 2017-10-03 17:15 UTC (permalink / raw)
  To: pgsql-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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Static variable inside PL/pgSQL (or) native C function
  2017-09-29 13:46 Static variable inside PL/pgSQL (or) native C function athinivas <athinivas@gmail.com>
  2017-09-29 14:04 ` Re: Static variable inside PL/pgSQL (or) native C function David G. Johnston <david.g.johnston@gmail.com>
  2017-10-03 17:15   ` Re: Static variable inside PL/pgSQL (or) native C function athinivas <athinivas@gmail.com>
@ 2017-10-03 17:25     ` Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Pavel Stehule @ 2017-10-03 17:25 UTC (permalink / raw)
  To: athinivas <athinivas@gmail.com>; +Cc: pgsql-sql

2017-10-03 19:15 GMT+02:00 athinivas <athinivas@gmail.com>:

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

No, it is not possible

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
>

^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2017-10-03 17:25 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-09-29 13:46 Static variable inside PL/pgSQL (or) native C function athinivas <athinivas@gmail.com>
2017-09-29 14:03 ` Pavel Stehule <pavel.stehule@gmail.com>
2017-09-29 14:04 ` David G. Johnston <david.g.johnston@gmail.com>
2017-10-03 17:15   ` athinivas <athinivas@gmail.com>
2017-10-03 17:25     ` Pavel Stehule <pavel.stehule@gmail.com>

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