Re: Getting NEW and OLD in ordinary functions.

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Rajesh Kumar Mallah <mallah(at)trade-india(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Getting NEW and OLD in ordinary functions.
Date: 2003-04-09 16:45:45
Message-ID: 200304090945.45334.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Rajesh,

> is it possible to access NEW , OLD rows in an ordinary function
> (function which are not TRIGGER PROCEDURES)

I do this all the time in a roundabout way.
1) I create a function that takes all the columns of the table as parameters.
2) Instead of doing an UPDATE or INSERT into the table, the client calls this
function.
3) I check all the data fed to the function. If I need to compare it to the
data on disk, I SELECT the "old" data into a RECORD and compare.
4) If everything's ok, I do an UPDATE or INSERT.

I have about 10,000 lines of PL/PgSQL doing this for various applications
where the data integrity logic is too complex for a trigger or check
constraint. It also allows me to implement a custom locking scheme and
return custom error messages. It works very well.

--
Josh Berkus
Aglio Database Solutions
San Francisco

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message mallah 2003-04-09 18:03:37 Re: Getting NEW and OLD in ordinary functions.
Previous Message Josh Berkus 2003-04-09 16:18:45 Re: [SQL] Yet Another (Simple) Case of Index not used