Re: Implementation of a bag pattern using rules

From: Mark Gibson <gibsonm(at)cromwell(dot)co(dot)uk>
To: Richard Sydney-Smith <richard(at)ibisaustralia(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Implementation of a bag pattern using rules
Date: 2004-02-09 17:42:25
Message-ID: 4027C681.3090102@cromwell.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Richard Sydney-Smith wrote:

>Mark,
>
>love the idea, guess I should have read it somewhere but haven't. Obvious
>and beautiful. Please let me know if you or someone else solves the initial
>double value.
>
>
>
I used to use functions for this kind of thing,
and was thinking that what SQL really needed was an 'UPDATE OR INSERT'
command,
then it suddenly came to me last night, it could be done with rules or
triggers.
[I've posted a trigger solution for the relative values separately, in
response to Tom Lanes help]

>Got me thinking of all the places I cold have used this instead of coding
>select/insert/update/delete.
>Also have you worked a solutions where both the abs and relative inserts
>apply to the same bag
>
>eg insert another apple vs set apples to 5
>
>
>
Hmmm, yeah, I'm wondering about that one. It would be handy.
Custom datatype maybe - an integer with a flag to indicate absolute or
relative???
eg:
INSERT INTO bag_test VALUES ('orange', '10 abs');
INSERT INTO bag_test VALUES ('orange', '-5 rel');

or views that modify an underlying table???
eg:
INSERT INTO bag_test_abs VALUES ('orange', 10);
INSERT INTO bag_test_rel VALUES ('orange', -5);

I have no idea yet whether these are possible though, any ideas?

>Much of my attitude to triggers has been non-committal. Your example changes
>that.
>
>
>
Triggers, rules and functions ROCK. It's allowed us to move all the
business logic into the
database itself so we can create really simple clients easily in any
language/environment.

Right, I'm off home now :)

Cheers

--
Mark Gibson <gibsonm |AT| cromwell |DOT| co |DOT| uk>
Web Developer & Database Admin
Cromwell Tools Ltd.
Leicester, England.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Marco Lazzeri 2004-02-09 18:12:13 Multiple outer join on same table
Previous Message Paul Thomas 2004-02-09 17:27:48 Re: Index not used - now me