On Mar 26, 4:40 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > What is the use-case for something like this in Django? The only times > we do SQL inserts are when we're saving a model instance or updating a > many-to-many relation. I can't see either of those really needing this > type of functionality, but I'd be interested to hear the use-case you > have in mind. > > Malcolm > > -- > Everything is _not_ based on faith... take my word for > it.http://www.pointy-stick.com/blog/
Sure. Let's say you've got a forum with a search function. One way to implement this is to catalog all the words in each post when the post is made. You've got two tables for this function, one that has a unique listing of words, 1 per row, and another table that maps each of those words to each post. For example, you might have a post with the text "Hi my name is Bob" Then you would have these tables if that post has a post_id of 5 table_words word_id word 1 'hi' 2 'python' 3 'name' 4 'my' 5 'monty' 6 'is' 7 'Bob' table_post_words post_id word_id 5 1 5 7 5 6 5 3 5 4 So if a user searches for the word "name", then they will get back all the posts that have an entry in table_post_words with a word_id of 3. After updating table_words to have any new unique entries, you then need to create an entry in table_post_words for each searchable word that appears. One way to do this is to use a SELECT to get all these entries and then iterate over that list to create them one at a time. Another way is to take the same SELECT statement and use it as a subquery to an INSERT, so that your db does all this for you. It might be preferred to do it this way if you don't want the overhead of passing all the entries back and forth between db and server. If I'm looking at this the wrong way, please let me know. :) Brian --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---