On 2011-09-29, Péter Szabó <matyee.nmi@gmail.com> wrote:
> users_has_cards.auctions + users_has_cards.decks never can be higher
> then users_has_cards.total. It should be also granted that
> users_has_cards.total - users_has_cards.auctions number of cards from
> a specific type can be in any decks.
>
> The deck assembly input comes from web, and parsed with PHP, so it is
> absolutely not trusted.
>
> I am started to write a PL/PgSQL function to handle the save of a
> deck, but it seems unable to solve this issue. I don't know how to go
> forward, so any idea is appreciated.
so users_has_cards has a check ( total >= decks + auctions )
and decks_has_cards needs triggers on insert, update, and delete that
manipulate the decks column of the users_has_cards record that
corresponds to that card.
This is probably goiung to make updates to the decks_has_cards table about
10 times slower (should still be faster than you could have done in PHP)
--
⚂⚃ 100% natural