pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: Rajesh Kumar Mallah <mallah@trade-india.com>
To: pgsql-sql@postgresql.org
Subject: Re: Getting NEW and OLD in ordinary functions.
Date: Wed, 9 Apr 2003 09:45:45 -0700
Message-ID: <200304090945.45334.josh@agliodbs.com> (raw)
In-Reply-To: <200304091551.02277.mallah@trade-india.com>
References: <200304091551.02277.mallah@trade-india.com>

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




view thread (7+ messages)  latest in thread

Message-ID: <200304090945.45334.josh@agliodbs.com>
Permalink:  ../200304090945.45334.josh@agliodbs.com/
Also on:    postgresql.org/message-id/200304090945.45334.josh@agliodbs.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: josh@agliodbs.com, mallah@trade-india.com
  Subject: Re: Getting NEW and OLD in ordinary functions.
  In-Reply-To: <200304090945.45334.josh@agliodbs.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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