merge in postgres trigger function

From: "Leon Match" <leon(dot)match(at)convergia(dot)net>
To: <pgsql-general(at)postgresql(dot)org>
Subject: merge in postgres trigger function
Date: 2011-06-17 21:35:39
Message-ID: 000001cc2d36$80dc0ad0$82942070$@match@convergia.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

I am trying to move few objects to postgres from oracle.

I have an issue with a trigger, which has a merge inside?

Here is my code:

BEGIN

MERGE INTO Requests r

using (select
new.web_form_id web_form_id,


new.form_type form_type,


new.submit_date submit_date,


new.email email,


new.custom_fields custom_fields


from DUAL) w

on
(r.request_id = new.web_form_id)

when not matched

THEN

insert
(


r.request_id,


r.form_type,


r.submit_date,


r.request_email,


r.request_description


)

values (


w.web_form_id,


w.form_type,


w.submit_date,


w.email,


w.custom_fields


)

when matched

then

update set

form_type =
NVL (w.form_type, r.form_type),

submit_date
= NVL (w.submit_date, r.submit_date),


request_email = NVL (w.email, r.request_email),


request_description = NVL (w.custom_fields, r.request_description);

end if;

END;

I receive an error - "Requests is not a known variable, Line 3: MERGE INTO
Requests r"

But "Requests" is a table is not a variable!

What is wrong with my statement? May be Merge is not legal in postgres
trigger functions?

What would be the way around?

Thank you,

Leon

leon(dot)match(at)convergia(dot)net

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2011-06-17 21:47:21 Re: Are check constraints always evaluated on UPDATE?
Previous Message bubba postgres 2011-06-17 21:25:10 Are check constraints always evaluated on UPDATE?