Created
September 16, 2011 13:23
-
-
Save tobiashm/1222122 to your computer and use it in GitHub Desktop.
SQL snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- initial | |
| UPDATE item SET depth = 0 WHERE parent_item_guid IS NULL; | |
| -- SQLite3 doesn't support loops, so run this until `select count(*) from item where product_code is null` = 0 | |
| INSERT OR REPLACE INTO item(item_guid, user_guid, parent_item_guid, name, depth) | |
| SELECT t.item_guid, t.user_guid, t.parent_item_guid, t.name, p.depth + 1 FROM item AS t | |
| INNER JOIN item AS p ON (t.parent_item_guid = p.item_guid) | |
| WHERE p.depth >= 0 | |
| AND NOT p.item_guid IS NULL | |
| AND t.depth IS NULL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment