Обсуждение: change a field

Поиск
Список
Период
Сортировка

change a field

От
Patrick Meylemans
Дата:
Dear,

I want to change a field of a record after the modification of another 
field of the same record or during an insert of a new record.

Suppose the following table

field        | type
----------------------------------
id        | serial
sign        | integer
value        | integer
real_value    | integer

When inserting a new record, giving values to sign and value, the field 
real_value should be the product of the fields sign and value.
When updating an existing record, the value of the field real_value should 
be recalculated.

I tried with plpgsql functions and triggers but with no success. It works 
only when inserting new records and not when updating a field.

What is the best way to solve this problem ?

Kind regards

Patrick Meylemans



Re: change a field

От
Peter Eisentraut
Дата:
Patrick Meylemans writes:

> What is the best way to solve this problem ?

Show us your code.

-- 
Peter Eisentraut   peter_e@gmx.net



Re: change a field

От
"A.Bhuvaneswaran"
Дата:
> I want to change a field of a record after the modification of another 
> field of the same record or during an insert of a new record.

You can easily accomplish this in a BEFORE trigger. It is applicable for 
both insert & update.

regards,
bhuvaneswaran



Re: change a field

От
Bruno Wolff III
Дата:
On Wed, Sep 10, 2003 at 22:12:45 +0200, Patrick Meylemans <Patrick.Meylemans@wtcm.be> wrote:
> 
> What is the best way to solve this problem ?

The best way is probably with a view.