Re: Error Message - Mailing list pgsql-general

From Michael Fuhr
Subject Re: Error Message
Date
Msg-id 20051027043803.GA61100@winnie.fuhr.org
Whole thread Raw
In response to Re: Error Message  (Bob Pawley <rjpawley@shaw.ca>)
List 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

pgsql-general by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: Seq Scan but I think it should be Index Scan
Next
From: Bruno Wolff III
Date:
Subject: Re: count( only if true)