PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 3rd, 2012, 04:09 AM
scob01 scob01 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 scob01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 45 m 41 sec
Reputation Power: 0
Trigger NEW problems inserting

Hi all
anyone know how to fix this?

I would like to delete all data match the md5() criteria.
the function
CREATE OR REPLACE FUNCTION dup_trigger()
RETURNS trigger AS
$BODY$
BEGIN
DELETE FROM target_data WHERE
dup_id=md5(NEW.type_id::text||NEW.country_id::TEXT||NEW."Date"::text);
INSERT INTO scriptcase.target_data VALUES (NEW.*,md5(NEW.type_id::text||NEW.country_id::TEXT||NEW."Date"::text));
Return NEW;
END;
$BODY$
LANGUAGE plpgsql;

and the error message:

[Err] ERROR: record "new" has no field "type_id"
CONTEXT: SQL statement "DELETE FROM target_data WHERE
OLD.dup_id=md5(NEW.type_id::text||NEW.country_id::TEXT||NEW."Date"::text)"
PL/pgSQL function dup_trigger() line 2 at SQL statement

please help I'm stuck

Thanks

Reply With Quote
  #2  
Old November 8th, 2012, 09:32 PM
rtz_andy rtz_andy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2010
Posts: 15 rtz_andy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 46 m 35 sec
Reputation Power: 0
Wink

Hi,

Since you didn't show the structure of your table, I think the column type_id is not existing on the table where you put your trigger.


Please see this example.

CREATE TABLE aav (id int, name text);
INSERT INTO aav SELECT 1,'drew';

CREATE TABLE aav2 (id int, name text, type_id int);
INSERT INTO aav2 SELECT 1,'drew', 1;


CREATE OR REPLACE FUNCTION aav_update() RETURNS TRIGGER AS $$
BEGIN
IF TG_OP='UPDATE' THEN
UPDATE aav2 SET name=a.name from aav a where a.id=aav2.id and a.id=new.type_id;
END IF;
END;
$$LANGUAGE PLPGSQL;

CREATE TRIGGER aav_trigger_update AFTER UPDATE ON aav FOR EACH ROW execute procedure aav_update();

UPDATE aav SET name='andrew' WHERE id=1;
ERROR: record "new" has no field "type_id"

It returned error because type_id is not existing on table aav where I created the trigger.

Hope this gives you an idea.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > Trigger NEW problems inserting

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap