473,385 Members | 1,311 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

UPDATE inside an Update trigger

I have a trigger that performs an UPDATE query on the same table that
the Update trigger is defined. Of course, it loops infinitely, is there
a way to do this?

CREATE OR REPLACE FUNCTION "public"."clear_common_groups" () RETURNS
trigger AS'
DECLARE
norows integer;
BEGIN
RAISE NOTICE ''Looking for common areas in Building
%'',NEW.hud_building_id;
IF NEW.common_area = ''t'' THEN
UPDATE tblhudunits SET common_area = NULL WHERE unit_id <>
NEW.unit_id AND hud_building_id = NEW.hud_building_id;
END IF;
IF NEW.exterior_area = ''t'' THEN
UPDATE tblhudunits SET exterior_area = NULL WHERE unit_id <>
NEW.unit_id AND hud_building_id = NEW.hud_building_id;
END IF;
GET DIAGNOSTICS norows = ROW_COUNT;
IF NOT FOUND THEN
RAISE NOTICE ''Nothing updated'';
ELSE
RAISE NOTICE ''% rows updated'',norows;
END IF;
RETURN NULL;
END;
'LANGUAGE 'plpgsql' IMMUTABLE CALLED ON NULL INPUT SECURITY INVOKER;

CREATE TRIGGER "insert_new_common_area" AFTER INSERT OR UPDATE
ON "public"."tblhudunits" FOR EACH ROW
EXECUTE PROCEDURE "public"."clear_common_groups"();

--
Robert
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #1
0 1004

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gent | last post by:
am using FOR UPDATE triggers to audit a table that has 67 fields. My problem is that this slows down the system significantly. I have narrowed down the problem to the size (Lines of code) that need...
8
by: Jan van Veldhuizen | last post by:
The UPDATE table FROM syntax is not supported by Oracle. I am looking for a syntax that is understood by both Oracle and SqlServer. Example: Table1: id name city ...
10
by: smorrey | last post by:
Hello all, I am writing an app in PHP that uses a PostGres database. One thing i have noticed is that what should/could be a single line of SQL code takes about 6 lines of PHP. This seem...
25
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
2
by: D. Dante Lorenso | last post by:
I'm trying to build a table that will store a history of records by enumerating the records. I want the newest record to always be number ZERO, so I created a trigger on my table to handle the...
0
by: Robert Fitzpatrick | last post by:
I have a trigger that performs an UPDATE query on the same table that the Update trigger is defined. Of course, it loops infinitely, is there a way to do this? CREATE OR REPLACE FUNCTION...
3
by: V T | last post by:
Hello all, SQL Server 2000 documentation http://www.microsoft.com/technet/prodtechnol/sql/2000/reskit/part10/c3761.mspx states that if view is using "NOT NULL" columns of a base table, then...
5
by: wpellett | last post by:
I can not get the SQL compiler to rewrite my SQL UPDATE statement to include columns being SET in a Stored Procedure being called from a BEFORE UPDATE trigger. Example: create table...
2
by: rodchar | last post by:
hey all, i have to buttons on a web form and i have an update panel with a single textbox inside it. i add a trigger to the update panel for one of the buttons. the button procedure assigns some...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.