views:

33

answers:

2

Hello,

since it is possible to do: INSERT INTO some_table VALUES (NEW.*) in pl/pgsql can we do something similar but for UPDATE clause using NEW ? I mean i want to update some row using values from NEW object.

Thanks in advance.

A: 

it is possible to do what you haved mentiened.please refer to the following link:

http://www.postgresql.org/docs/current/interactive/plpgsql-trigger.html

tinychen
A: 

I did not find any solution to solve my problem in http://www.postgresql.org/docs/current/interactive/plpgsql-trigger.html so I'll explain a little bit more what I want to achieve.

When I insert a new record to table "SomeTable" I want to:

  1. Check if some record already exists, relating on value from NEW ie. select * From SomeTable Where related_id = NEW.related_id
  2. IF the record is found I want to update it and prevent the insertion of a new one.
  3. If it is not found I want to insert it.

Points 1 and 3 are easy to implement. However, I don't know how can I update a row using values from NEW object. The important thing is I will not know the structure of a record, that's why I can't simply do: Update SomeTable name = New.name Where id= someId

Thats why I am looking for some more generic way to to this, something like:

update sometable set * = NEw.*
koszikot