Re: Referencing external table in update/insert triggers

Поиск
Список
Период
Сортировка
От Amitabh Kant
Тема Re: Referencing external table in update/insert triggers
Дата
Msg-id 84b68b3d1002180133x549f2b07p6d40682cd94d1d86@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Referencing external table in update/insert triggers  (Richard Huxton <dev@archonet.com>)
Список pgsql-sql
<br /><br /><div class="gmail_quote">On Thu, Feb 18, 2010 at 2:53 PM, Richard Huxton <span dir="ltr"><<a
href="mailto:dev@archonet.com">dev@archonet.com</a>></span>wrote:<br /><blockquote class="gmail_quote"
style="margin:0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">On
17/02/1015:18, Amitabh Kant wrote:<br /><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left:
1pxsolid rgb(204, 204, 204); padding-left: 1ex;"><br /> CREATE OR REPLACE FUNCTION update_data() RETURNS TRIGGER AS
$update_data$<br/> BEGIN<br />     IF NEW.t1f4>  t2.t2f4<br />         UPDATE t2 set t2f2=NEW.t1f2, t2f3=NEW.t1f3,
t2f4=NEW.t1f4where<br /> t2f1=NEW.d1;<br />         RETURN NEW;<br />     END IF;<br /> END;<br /> $update_data$
LANGUAGEplpgsql;<br /></blockquote><br /></div><div class="im"><blockquote class="gmail_quote" style="margin: 0pt 0pt
0pt0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"> I would like to compare the date present in
thet2f4 with the new data being<br /> updated through the trigger.  Using the if line as listed above returns an<br />
error.<br/></blockquote><br /></div> You can always do something like:<br />  SELECT t2.t2f4 INTO my_variable FROM t2
WHERE...<br />  IF NEW.t1f4 > my_variable<br /><br /> However, for this case you can just do an update with an
extendedwhere clause:<br />  UPDATE t2 ... WHERE t2f1=NEW.d1 AND NEW.t1f4 > t2.t2f4<br /><br /> No need for the
IF.<br/><font color="#888888"><br /> -- <br />  Richard Huxton<br />  Archonet Ltd<br /></font></blockquote></div><br
/><br/>Thanks Richard. <br /><br />With regards<br /><br />Amitabh Kant<br /> 

В списке pgsql-sql по дате отправления:

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: Referencing external table in update/insert triggers
Следующее
От: zkn
Дата:
Сообщение: Problem with batch insert