X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 8F48CD1B262 for ; Thu, 22 Jul 2004 20:15:57 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 01875-07 for ; Thu, 22 Jul 2004 23:15:51 +0000 (GMT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id D2894D1B1BE for ; Thu, 22 Jul 2004 20:15:48 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id i6MNFlqb021485 for ; Thu, 22 Jul 2004 23:15:48 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i6MMjoDt017998 for pgsql-sql@postgresql.org; Thu, 22 Jul 2004 22:45:50 GMT From: ohmy9od@yahoo.com (Oeln) X-Newsgroups: comp.databases.postgresql.sql Subject: Re: Issue with plpgsql trigger Date: 22 Jul 2004 15:45:52 -0700 Organization: http://groups.google.com Lines: 67 Message-ID: References: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: groups-abuse@google.com To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.7 tagged_above=0.0 required=5.0 tests=FORGED_YAHOO_RCVD, UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200407/240 X-Sequence-Number: 18492 Only wanted to indicate further that I know that IF loop is bad logic in itself, where oper will get overwritten in each case. I've now got the following instead: CREATE FUNCTION online_pct_trig() RETURNS opaque AS ' DECLARE i1hr timestamp; i1day timestamp; i1wk timestamp; i1mo timestamp; i1yr timestamp; oper varchar; BEGIN SELECT o.isodt1hr INTO i1hr, o.isodt1day INTO i1day, o.isodt1wk INTO i1wk, o.isodt1mo INTO i1mo, o.isodt1yr INTO i1yr FROM online_pct o WHERE o.id = NEW.id; IF i1hr <= (now() - ''00:01''::interval) THEN oper := ''SELECT online_pct_func(NEW.id, ''; oper := oper || ''01:00'' || '');''; EXECUTE oper; END IF; IF i1day < (now() - ''01:00''::interval) THEN oper := ''SELECT online_pct_func(NEW.id, ''; oper := oper || ''1 day'' || '');''; EXECUTE oper; END IF; IF i1wk < (now() = ''1 day''::interval) THEN oper := ''SELECT online_pct_func(NEW.id, ''; oper := oper || ''1 week'' || '');''; EXECUTE oper; END IF; IF i1mo < (now() - ''1 week''::interval) THEN oper := ''SELECT online_pct_func(NEW.id, ''; oper := oper || ''1 mon'' || '');''; EXECUTE oper; END IF; IF i1yr < (now() - ''1 mon''::interval) THEN oper := ''SELECT online_pct_func(NEW.id, ''; oper := oper || ''1 year'' || '');''; EXECUTE oper; END IF; RETURN NEW; END; ' LANGUAGE 'plpgsql'; CREATE TRIGGER online_pct_trig AFTER INSERT ON info FOR EACH ROW EXECUTE PROCEDURE online_pct_trig(); I get no errors when I create it; but it isn't invoking the function either - that's what the issue is, but I'm not certain why or what I've got to correct in order to get it to work. Thank for any input.. - Oeln