Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > Re: Is this pos...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 8 Topic 15474 of 17437
Post > Topic >>

Re: Is this possible in a trigger?

by valgog <valgog@[EMAIL PROTECTED] > May 7, 2008 at 04:04 AM

On May 6, 11:05=A0pm, ferna...@[EMAIL PROTECTED]
 (Fernando) wrote:
> I want to keep a history of changes on a field in a table. =A0This will
be=

> the case in multiple tables.
>
> Can I create a trigger that loops the OLD and NEW values and compares
> the values and if they are different creates a change string as follows:
>
> e.g;
>
> FOR EACH field IN NEW
> =A0 =A0 IF field.value <> OLD.field.name THEN
> =A0 =A0 =A0 =A0changes :=3D changes
> =A0 =A0 =A0 =A0 =A0 =A0 || field.name
> =A0 =A0 =A0 =A0 =A0 =A0 || ' was: '
> =A0 =A0 =A0 =A0 =A0 =A0 || OLD.field.value
> =A0 =A0 =A0 =A0 =A0 =A0 || ' now is: '
> =A0 =A0 =A0 =A0 =A0 =A0 || field.value
> =A0 =A0 =A0 =A0 =A0 =A0 || '\n\r';
> =A0 =A0 END IF
> END FOR;
>
> Your help is really appreciated.
>
> Thank you.

in plpgsql you could

select new into textVar;

and then do acrobatics with the text value of that record... or
converting the text value into a known table record type with EXECUTE
'select ' || quote_literal(textVar) || '::tableRecord' INTO
tableRecordVar statement. But the field names are to be extracted from
the catalog anyway.

Or use plperl or plpython :(
 




 8 Posts in Topic:
Is this possible in a trigger?
fernando@[EMAIL PROTECTED  2008-05-06 17:05:37 
Re: Is this possible in a trigger?
kgore4@[EMAIL PROTECTED]   2008-05-07 10:10:50 
Re: Is this possible in a trigger?
kreno@[EMAIL PROTECTED]   2008-05-06 19:13:29 
Re: Is this possible in a trigger?
xzilla@[EMAIL PROTECTED]   2008-05-07 01:12:25 
Re: Is this possible in a trigger?
fernando@[EMAIL PROTECTED  2008-05-07 09:37:21 
Re: Is this possible in a trigger?
kreno@[EMAIL PROTECTED]   2008-05-07 08:16:01 
Re: Is this possible in a trigger?
depesz@[EMAIL PROTECTED]   2008-05-07 13:01:35 
Re: Is this possible in a trigger?
valgog <valgog@[EMAIL   2008-05-07 04:04:21 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 12:15:05 CST 2008.