Rules Question
От | Charles Tassell |
---|---|
Тема | Rules Question |
Дата | |
Msg-id | 4.1.19990830074918.00a0f100@mailer.isn.net обсуждение исходный текст |
Список | pgsql-sql |
I have a question on using INSERT rules. What I am attempting to do is to create a rule that checks to see if the item being inserted already exists.If it does exist, increase the stored quantitybye the NEW.quantity, otherwise, just handle the INSERT as normal. Here is what I've tried CREATE TABLE orders (cust_id int,item_id text,quantity int ); CREATE RULE combine_dupes AS ON INSERT TO orders WHERE NEW.item_id IN (SELECT item_id FROM orders WHERE cust_id= NEW.cust_id AND item_id = NEW.item_id) DO UPDATE orders SET quantity = NEW.quantity + quantity WHEREcart_id = NEW.cart_id AND item_ID = NEW.item_id; I've also tried it as a DO INSTEAD and without the "AND item_id = NEW.item_id" clause (which shouldn't be needed) but they don't work either. So, what's the deal? Am I making a syntax error, or do I need to use a function or trigger in order to do what I'm trying? BTW: Please respond or cc directly to me, I only subscribe to pgsql-general, I just thought this was more SQL related.
В списке pgsql-sql по дате отправления: