Journal Journal: Silly SQL trick 2
Tonight's task is to manually categorize a rather flat tree structure in SQL (currently two levels only) by reading the top level entry and assigning it and its children to a category. On a lark I gave this a shot:
update tree set category=1 where 5 in (id,parent);
and it worked in PostgreSQL.
Why? Because I'm sitting here reading the list of top-level entries in one window while using psql in the other and pressing up to edit the previous query. Before I tried that I had
update tree set category=1 where id=4 or parent=4
so I'd have to retype TWO numbers instead of just one.