From: Kent L. Nasveschuk <kent@wareham.k12.ma.us>
To: Postgres-Admin list <pgsql-admin@postgresql.org>
Subject: Trigger function
Date: 13 Dec 2003 13:55:38 -0500
Message-ID: <1071341736.2220.175.camel@1134> (raw)
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 <kent@wareham.k12.ma.us>
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-admin@postgresql.org
Cc: kent@wareham.k12.ma.us
Subject: Re: Trigger function
In-Reply-To: <1071341736.2220.175.camel@1134>
References: <1071341736.2220.175.camel@1134>
* 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