X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 8E231D1DD95 for ; Sat, 13 Dec 2003 18:56:14 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 26171-02 for ; Sat, 13 Dec 2003 14:55:53 -0400 (AST) Received: from rwcrmhc12.comcast.net (rwcrmhc12.comcast.net [216.148.227.85]) by svr1.postgresql.org (Postfix) with ESMTP id 2E263D1DDA9 for ; Sat, 13 Dec 2003 14:55:41 -0400 (AST) Received: from [172.16.0.30] (h00508bcfaaed.ne.client2.attbi.com[65.96.103.108]) by comcast.net (rwcrmhc12) with SMTP id <20031213185541014000tldte>; Sat, 13 Dec 2003 18:55:42 +0000 Subject: Trigger function From: "Kent L. Nasveschuk" To: Postgres-Admin list Content-Type: text/plain Organization: Message-Id: <1071341736.2220.175.camel@1134> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-5) Date: 13 Dec 2003 13:55:38 -0500 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200312/182 X-Sequence-Number: 11689 Hello, I'm trying to write a trigger that upon inserting a value in a table another table is decremented. Something that could be used in an inventory system, for example. I know it can be done easily outside POSTGRES with PHP but in this case I would like the database to handle it. Example: create table order ( order_number integer not null default nextval('order_number_seq'::text), itemid number integer references inventory, item_amt integer, cost numeric(3,2), constraint order_pk primary key(order_number) ); create table inventory ( itemid integer not null default nexval('itemid_seq'::text), onhand integer not null default 0, onorder integer not null default 0, desc varchar(30) not null, cost numeric(3,2) not null, constraint inventory_pk primary key(itemid) ); Can you give me some direction on how to do this. In this case decrement the inventory by the amount of the order for that particular item. I'm not sure how to pass variables to triggers and/or functions. Thank you -- Kent L. Nasveschuk