472,809 Members | 2,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

INSERT BEFORE Trigger

Anytime I create an INSERT BEFORE trigger that includes a query on the
same table as the trigger is assigned, the insert does not happen
without error. I get 'INSERT 0 0'. It is like the query loses the insert
information, is this something that can't be done?

DECLARE
checkit record;
BEGIN
SELECT INTO checkit MAX(public.tblhudunits.sort_order) AS maximum,
MIN(public.tblhudunits.sort_order) AS minimum FROM public.tblhudunits
WHERE (public.tblhudunits.hud_building_id = NEW.hud_building_id);
IF FOUND THEN
IF (NEW.sort_order >= checkit.minimum AND NEW.sort_order <=
checkit.maximum) THEN
RAISE EXCEPTION 'Sort Order cannot be between % and %',
checkit.minimum, checkit.maximum;
EXIT;
END IF;
END IF;
RETURN NULL;
END;

--
Robert
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #1
2 1893

On Sat, 19 Jun 2004, Robert Fitzpatrick wrote:
Anytime I create an INSERT BEFORE trigger that includes a query on the
same table as the trigger is assigned, the insert does not happen
without error. I get 'INSERT 0 0'. It is like the query loses the insert
information, is this something that can't be done?

DECLARE
checkit record;
BEGIN
SELECT INTO checkit MAX(public.tblhudunits.sort_order) AS maximum,
MIN(public.tblhudunits.sort_order) AS minimum FROM public.tblhudunits
WHERE (public.tblhudunits.hud_building_id = NEW.hud_building_id);
IF FOUND THEN
IF (NEW.sort_order >= checkit.minimum AND NEW.sort_order <=
checkit.maximum) THEN
RAISE EXCEPTION 'Sort Order cannot be between % and %',
checkit.minimum, checkit.maximum;
EXIT;
END IF;
END IF;
RETURN NULL;


You do not want to return NULL from a before trigger generally. Returning
NULL effectively means suppress this operation. I think you probably want
RETURN NEW;
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #2

On Sat, 19 Jun 2004, Robert Fitzpatrick wrote:
Anytime I create an INSERT BEFORE trigger that includes a query on the
same table as the trigger is assigned, the insert does not happen
without error. I get 'INSERT 0 0'. It is like the query loses the insert
information, is this something that can't be done?

DECLARE
checkit record;
BEGIN
SELECT INTO checkit MAX(public.tblhudunits.sort_order) AS maximum,
MIN(public.tblhudunits.sort_order) AS minimum FROM public.tblhudunits
WHERE (public.tblhudunits.hud_building_id = NEW.hud_building_id);
IF FOUND THEN
IF (NEW.sort_order >= checkit.minimum AND NEW.sort_order <=
checkit.maximum) THEN
RAISE EXCEPTION 'Sort Order cannot be between % and %',
checkit.minimum, checkit.maximum;
EXIT;
END IF;
END IF;
RETURN NULL;


You do not want to return NULL from a before trigger generally. Returning
NULL effectively means suppress this operation. I think you probably want
RETURN NEW;
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #3

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

Similar topics

4
by: DTB | last post by:
I am having trouble creating an INSTEAD OF trigger in SQL Server to replicate a BEFORE UPDATE trigger from ORACLE. Here is a sample of the ORACLE BEFORE UPDATE trigger: CREATE TRIGGER myTRIGGER ON...
1
by: shottarum | last post by:
I currently have 2 tables as follows: CREATE TABLE . ( mhan8 int, mhac02 varchar(5), mhmot varchar(5), mhupmj int )
9
by: Martin | last post by:
Hello, I'm new with triggers and I can not find any good example on how to do the following: I have two tables WO and PM with the following fields: WO.WONUM, VARCHAR(10) WO.PMNUM,...
4
by: brent.ryan | last post by:
How do I get the next int value for a column before I do an insert in MY SQL Server 2000? I'm currently using Oracle sequence and doing something like: select seq.nextval from dual; Then I...
2
by: 73blazer | last post by:
Perhaps my thinking is wrong but this is what I have: 1 table (Tab1) with 1 attribute (Attr1) Attr1 char(16) for bit data ----------------------------------------------- create trigger...
1
by: abhi81 | last post by:
Hello All, I have a table on which I have created a insert,Update and a Delete trigger. All these triggers write a entry to another audit table with the unique key for each table and the timestamp....
1
by: filip1150 | last post by:
I'm trying to find if there is any performance diference between explicitly using a sequence in the insert statement to generate values for a column and doing this in an insert trigger. I...
1
by: veasnamuch | last post by:
I have a problem while I create a trigger to my table. My objective is getting any change made to my table and record it in to another table . My have thousands records before I add new trigger to...
2
by: gimme_this_gimme_that | last post by:
I'm using DB2 8.1. Suppose table foo has columns name and lname: create table foo (name as varchar(200), lname as varchar(200)); Write a trigger that inserts the lower case value of name...
2
by: lenygold via DBMonster.com | last post by:
Hi Everebody: I have a table: CREATE TABLE CROSS_REFERENCE (ROW# INTEGER NOT NULL ,KEY_WORD CHAR(16) NOT NULL ,QUERY_DESCR VARCHAR(330) NOT NULL ,PRIMARY KEY (ROW#,KEY_WORD)); It is a...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.