Search for sample pg stored procedure - Mailing list pgsql-general

From Dwayne Miller
Subject Search for sample pg stored procedure
Date
Msg-id 3E553A4A.3030808@espgroup.net
Whole thread Raw
List pgsql-general
I'm looking for a stored procedure example to do the following:

Given a table something like

create table audit (
  aid serial,
  amount float,
  balance float,
  parent aid int)

the sp would be used to find the last entry in the table, take the
balance from that entry and add it to the current amount and do an
insert back into the same table. This would of course grab a lock on the
table so that two pending inserts would occur sequentially.  The order
in that case would not be significant as long as the second insert used
the results of the first insert.

I'm really not sure how to do the locking in such an example.

Thanks in advance for any help,
Dwayne


pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: Table Partitioning in Postgres:
Next
From: P G
Date:
Subject: Re: What is the quickest query in the database?