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 1A395D1DB9D for ; Sun, 14 Dec 2003 17:29:42 +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 29998-02 for ; Sun, 14 Dec 2003 13:29:13 -0400 (AST) Received: from sycorax.affordablehost.com (sycorax.affordablehost.com [216.46.192.84]) by svr1.postgresql.org (Postfix) with ESMTP id EEA4DD1B47D for ; Sun, 14 Dec 2003 13:29:13 -0400 (AST) Received: from h0040054d8ee4.ne.client2.attbi.com ([66.31.57.228] helo=e-greek.net) by sycorax.affordablehost.com with asmtp (TLSv1:RC4-MD5:128) (Exim 4.24) id 1AVa3D-00079y-UA; Sun, 14 Dec 2003 12:29:04 -0500 Message-ID: <3FDC9DDD.3000607@e-greek.net> Date: Sun, 14 Dec 2003 12:29:01 -0500 From: Andrew Biagioni User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5a) Gecko/20030718 X-Accept-Language: en-us, en, it, it-ch, fr-fr, fr-ch, de-de, de-ch MIME-Version: 1.0 To: Postgres-Admin list Subject: Re: Trigger function References: <1071341736.2220.175.camel@1134> In-Reply-To: <1071341736.2220.175.camel@1134> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - sycorax.affordablehost.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - e-greek.net X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200312/184 X-Sequence-Number: 11691 Kent, I suggest you read: http://www.postgresql.org/docs/7.3/interactive/plpgsql-trigger.html I found it very useful myself, and it should answer (almost?) all your questions. Note that you will need to add either pl/pgsql or pl/TCL to your database to do triggers. The docs. for both languages are at: http://www.postgresql.org/docs/7.3/interactive/programmer-pl.html Andrew Kent L. Nasveschuk wrote: >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 > > > >