From: Michael Fuhr <mike@fuhr.org>
To: Bob Pawley <rjpawley@shaw.ca>
Cc: Terry Lee Tucker <terry@esc1.com>
Cc: Postgre General <pgsql-general@postgresql.org>
Subject: Re: Error Message
Date: Wed, 26 Oct 2005 22:38:03 -0600
Message-ID: <20051027043803.GA61100@winnie.fuhr.org> (raw)
In-Reply-To: <001601c5daa0$d2e717f0$ac1d4318@OWNER>
References: <03a301c5da6e$a20b6280$ac1d4318@OWNER>
<11706.1130361821@sss.pgh.pa.us>
<041401c5da84$7429ec90$ac1d4318@OWNER>
<200510261945.19824.terry@esc1.com>
<20051027010006.GA59813@winnie.fuhr.org>
<001601c5daa0$d2e717f0$ac1d4318@OWNER>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: mike@fuhr.org, rjpawley@shaw.ca, terry@esc1.com
Subject: Re: Error Message
In-Reply-To: <20051027043803.GA61100@winnie.fuhr.org>
References: <03a301c5da6e$a20b6280$ac1d4318@OWNER> <11706.1130361821@sss.pgh.pa.us> <041401c5da84$7429ec90$ac1d4318@OWNER> <200510261945.19824.terry@esc1.com> <20051027010006.GA59813@winnie.fuhr.org> <001601c5daa0$d2e717f0$ac1d4318@OWNER> <20051027043803.GA61100@winnie.fuhr.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox