Re: Error Message

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Bob Pawley <rjpawley(at)shaw(dot)ca>
Cc: Terry Lee Tucker <terry(at)esc1(dot)com>, Postgre General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Error Message
Date: 2005-10-27 04:38:03
Message-ID: 20051027043803.GA61100@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Oct 26, 2005 at 07:47:51PM -0700, Bob Pawley wrote:
> I have a base table called "process". Each row of this table is anchored by
> a serial column labeled "fluid_id".

What do you mean by "anchored by"? Is fluid_id the primary key for
process? Or is fluid_id a foreign key reference to some other
table? Or do you mean something else?

> After data has been entered into a row in "process", I want to trigger a
> row in another table labeled "specification" also with a column labeled
> "fluid_id". I would like this number from "process" entered into
> "specification" as an integer.

By "trigger a row" do you mean that you want the trigger on process
to insert a new row into specification? Is the following example
close to what you're looking for?

CREATE TABLE process (fluid_id integer PRIMARY KEY);
CREATE TABLE specification (fluid_id integer NOT NULL);

CREATE FUNCTION base() RETURNS trigger AS $$
BEGIN
INSERT INTO specification (fluid_id) VALUES (NEW.fluid_id);
RETURN NULL; -- ignored in AFTER triggers
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER trig1 AFTER INSERT ON process
FOR EACH ROW EXECUTE PROCEDURE base();

INSERT INTO process (fluid_id) VALUES (123);
INSERT INTO process (fluid_id) VALUES (456);

SELECT * FROM process;
fluid_id
----------
123
456
(2 rows)

SELECT * FROM specification;
fluid_id
----------
123
456
(2 rows)

--
Michael Fuhr

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruno Wolff III 2005-10-27 04:46:51 Re: count( only if true)
Previous Message Michael Fuhr 2005-10-27 04:05:22 Re: Seq Scan but I think it should be Index Scan