Re: Implementation of a bag pattern using rules

Поиск
Список
Период
Сортировка
От Mark Gibson
Тема Re: Implementation of a bag pattern using rules
Дата
Msg-id 4027C681.3090102@cromwell.co.uk
обсуждение исходный текст
Ответ на Re: Implementation of a bag pattern using rules  ("Richard Sydney-Smith" <richard@ibisaustralia.com>)
Список 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.



В списке pgsql-sql по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Index not used - now me
Следующее
От: Paul Thomas
Дата:
Сообщение: Re: Index not used - now me