473,799 Members | 2,761 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trigger Update Issue

Hello All

I'm running 7.3.4-1 on a RH9 box. I'm having a problem with a trigger
that seems to execute without actually performing the update that it
should. The update returns true everytime however if it is the first time
that the trigger executes on a given row, the column is not updated. The
column is updated correctly on subsequent calls.

Here is the code:

create table tabA (
id char(32) primary key not null,
Acol1 char(40) not null unique,
Acol2 integer not null,
Acol3 integer default 0 check ( Acol3 >= 0),
);

create table tabB (
id integer default nextval('tabB_i d_seq'::text)
not null check (id > 0) primary key,
tabA_id char(32) not null references tabA (id)
on delete cascade on update cascade,
Bcol1 text default null,
Bcol2 text default null,
);
CREATE OR REPLACE FUNCTION "tabB_postinser t" () RETURNS TRIGGER AS '
--
-- Actions to take after inserting into tabB
--
BEGIN
-- Increment tabA.attachment s
UPDATE tabA SET Acol3 = Acol3 + 1 WHERE id = NEW.tabA_id;
-- done
RETURN NEW;
END; ' LANGUAGE 'plpgsql';

CREATE TRIGGER "master_tabB_po stinsert"
AFTER INSERT ON "tabB"
FOR EACH ROW EXECUTE PROCEDURE "tabB_postinser t" ();

I am using this same trigger structure on other tables without having any
issues. Any insight would be greatly appreciated.

Thanks

-b

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #1
3 3433
On Friday 05 March 2004 14:00, beer wrote:
Hello All

I'm running 7.3.4-1 on a RH9 box. I'm having a problem with a trigger
that seems to execute without actually performing the update that it
should. The update returns true everytime however if it is the first time
that the trigger executes on a given row, the column is not updated. The
column is updated correctly on subsequent calls.
Perhaps put some debug code in and insert into tabB manually
CREATE OR REPLACE FUNCTION "tabB_postinser t" () RETURNS TRIGGER AS '
--
-- Actions to take after inserting into tabB
-- DECLARE
numrows int4;
BEGIN
-- Increment tabA.attachment s
UPDATE tabA SET Acol3 = Acol3 + 1 WHERE id = NEW.tabA_id; GET DIAGNOSTICTS numrows = ROW_COUNT;
RAISE NOTICE ''Updated % rows with id = %'',numrows, NEW.tabA_id; -- done
RETURN NEW;
END; ' LANGUAGE 'plpgsql';


Insert into tabB from psql and you should see a NOTICE message telling you
what is happening.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #2
Richard

Thanks for the suggestion. I had tried something similar using FOUND but
that didnt not give me the number of rows touched.

According to the output, 1 row was updated, however when I select on the
row the value is still 0.

-b
On Friday 05 March 2004 14:00, beer wrote:
Hello All

I'm running 7.3.4-1 on a RH9 box. I'm having a problem with a trigger
that seems to execute without actually performing the update that it
should. The update returns true everytime however if it is the first
time
that the trigger executes on a given row, the column is not updated.
The
column is updated correctly on subsequent calls.


Perhaps put some debug code in and insert into tabB manually
CREATE OR REPLACE FUNCTION "tabB_postinser t" () RETURNS TRIGGER AS '
--
-- Actions to take after inserting into tabB
--

DECLARE
numrows int4;
BEGIN
-- Increment tabA.attachment s
UPDATE tabA SET Acol3 = Acol3 + 1 WHERE id = NEW.tabA_id;

GET DIAGNOSTICTS numrows = ROW_COUNT;
RAISE NOTICE ''Updated % rows with id = %'',numrows, NEW.tabA_id;
-- done
RETURN NEW;
END; ' LANGUAGE 'plpgsql';


Insert into tabB from psql and you should see a NOTICE message telling you
what is happening.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 23 '05 #3
"beer" <be**@cmu.edu > writes:
I'm running 7.3.4-1 on a RH9 box. I'm having a problem with a trigger
that seems to execute without actually performing the update that it
should. The update returns true everytime however if it is the first time
that the trigger executes on a given row, the column is not updated. The
column is updated correctly on subsequent calls.


I couldn't reproduce this. I created the tables and trigger and then
did:

regression=# insert into tabA values('id1','c ol1', 2, 32);
INSERT 154119 1
regression=# insert into tabB values(1,'id1', 'col1','col2');
INSERT 154120 1
regression=# select * from tabA;
id | acol1 | acol2 | acol3
----------------------------------+------------------------------------------+-------+-------
id1 | col1 | 2 | 33
(1 row)

regression=# insert into tabB values(2,'id1', 'col1','col2');
INSERT 154121 1
regression=# select * from tabA;
id | acol1 | acol2 | acol3
----------------------------------+------------------------------------------+-------+-------
id1 | col1 | 2 | 34
(1 row)

It looks fine to me ... what are you doing differently?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #4

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

Similar topics

1
6175
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 to be compiled after the trigger has been fired. There is about 67 IF Update(fieldName) inside the trigger and a not very complex select statement inside the if followed by an insert to the audit table. When I leave only a few IF-s in the...
3
7282
by: takilroy | last post by:
Hi, Does anyone know of a simple way to do this? I want to create an insert trigger for a table and if the record already exists based on some criteria, I want to update the table with the values that are passed in via the insert trigger without having to use all the 'set' statements for each field (so if we add fields in the future I won't have to update the trigger). In other words, I want the trigger code to look something like...
18
5987
by: Bill Smith | last post by:
The initial row is inserted with the colPartNum column containing a valid LIKE pattern, such as (without the single quotes) 'AB%DE'. I want to update the column value with the results of a query against a different table (that uses the LIKE predicate) but cannot get around the SQL0132 error . I have tried the hex notation after the LIKE such as (without the quotes)... " where colNewPartNum like ( X'27' || nnn.colPartNum || X'27) " ,...
3
3421
by: Ricardo Corsi | last post by:
Hi, It is possible to call a trigger (inside a sql server..) with asp.net ? how can i do that ? thks!
6
2289
by: Robert Fitzpatrick | last post by:
On 7.4.2 I have a trigger that I want to update any existing boolean values to false if a new one in that group is declare true by inserting a new record or updating an existing record: ohc=# CREATE OR REPLACE FUNCTION "public"."clear_common_groups" () RETURNS trigger AS' ohc'# BEGIN ohc'# IF NEW.common_area = ''t'' THEN ohc'# UPDATE tblhudunits SET common_area = ''f'' WHERE hud_building_id = NEW.hud_building_id;
9
2750
by: steven | last post by:
Does anyone know how to do the following. I'm trying to mimic replication with triggers. I have 2 databases, each have these 2 tables. 1. USERS ID int NAME varchar(20)
13
6577
by: dennis | last post by:
Hello, I'm having trouble solving the following problem with DB2 UDB 8.2. I need to create a trigger that performs certain extra constraint validations (temporal uniqueness). One of the tables has no primary key. I'm having trouble expressing an update trigger that checks for existing rows, contemporary to the updated one, but exclusing the
8
7883
by: Benzine | last post by:
Hi, I have an issue with my replication at the moment. I will try to describe the scenario accurately. I am using MS SQL 2000 SP4 with Merge Replication. Subscribers connect to the publisher to upload/download changes. I have a trigger set up on one table which updates another, here is an example of the trigger: "CREATE TRIGGER qt_t_projTotal ON dbo.qt_quotes
2
4314
by: paulmac106 | last post by:
Hi, I need to update a field in about 20 records on a table. The table has an update trigger (which updates the field whenever a record is updated). As a result I'm getting an error: "Subquery returned more than 1 value.", and the update fails. Is there a way in the stored procedure to handle this issue? thanks for your help.
11
7883
by: tracy | last post by:
Hi, I really need help. I run this script and error message appeal as below: drop trigger log_errors_trig; drop trigger log_errors_trig ERROR at line 1: ORA04080: trigger 'LOG_ERRORS-TRIG' does not exist drop table log_errors_tab;
1
10231
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9073
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7565
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.