On Wed, Jun 03, 2009 at 09:11:23PM +0200, Jan scratched on the wall: > I thought about the adjacency lists. The columns would basically look > like this I guess: > > animal_id (PK), animal_id (father), aninmal_id (mother) > > Since I cant do a loop in sql how could I build a trigger securing, that > no child is e.g a father of it's own father (or grand-father and so on)? > To achieve that I would have to loop through the whole hierarchy of > ancestors.
You can't with just SQL. This is the whole issue with adjacency lists. Most basic operations, like finding ancestor lists, counting tree depths, finding a list of all children or descendants, etc., require some kind of loop. I suppose you could write some C function that did the verification for your trigger, but most of the basic "tree-like" operations have to be done by the application or some logic level above SQL itself. -j -- Jay A. Kreibich < J A Y @ K R E I B I.C H > "Our opponent is an alien starship packed with atomic bombs. We have a protractor." "I'll go home and see if I can scrounge up a ruler and a piece of string." --from Anathem by Neal Stephenson _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users