pl/pgsql question

From: Tim Perdue <tim(at)perdue(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: pl/pgsql question
Date: 2002-12-18 04:12:27
Message-ID: 3DFFF5AB.1080004@perdue.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I have created a function in pl/pgsql to modify a row before it gets put
into the database, but it seems my modification is being ignored, and
the unmodified row is being inserted.

I have confirmed with this RAISE EXCEPTION that my "NEW" row is modified
properly, however it is not being stored in the db.

NEW.start_date := NEW.start_date+delta;
-- RAISE EXCEPTION ''new start date: % '',NEW.start_date;
NEW.end_date := NEW.end_date+delta;

It's probably something very obvious, but I'm mystified.

Tim

--
-- Function to enforce dependencies in the table structure
--
CREATE OR REPLACE FUNCTION projtask_insert_depend () RETURNS OPAQUE AS '
DECLARE
dependent RECORD;
delta INTEGER;
BEGIN
--
-- First make sure we start on or after end_date of tasks
-- that we depend on
--
FOR dependent IN SELECT * FROM project_depend_vw
WHERE
project_task_id=NEW.project_task_id LOOP
--
-- See if the task we are dependent on
-- ends after we are supposed to start
--
IF dependent.end_date > NEW.start_date THEN
delta := dependent.end_date-NEW.start_date;
-- RAISE EXCEPTION ''delta: % '',delta;
NEW.start_date := NEW.start_date+delta;
-- RAISE EXCEPTION ''new start date: %
'',NEW.start_date;
NEW.end_date := NEW.end_date+delta;
END IF;

END LOOP;
RETURN NEW;
END;
' LANGUAGE 'plpgsql';

CREATE TRIGGER projtask_insert_depend_trig AFTER INSERT ON project_task
FOR EACH ROW EXECUTE PROCEDURE projtask_insert_depend();

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2002-12-18 04:26:18 Re: pl/pgsql question
Previous Message Peter Gabriel 2002-12-17 19:42:08 handling error in a function