Search Postgresql Archives

Re: Error Message

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux