Created
November 8, 2017 09:03
-
-
Save alexesDev/efbc35b8ae0f667aecbde4608d83de23 to your computer and use it in GitHub Desktop.
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
| WITH RECURSIVE tree AS ( | |
| SELECT id, parent_path, ARRAY[]::INTEGER[] AS ancestors | |
| FROM core.items | |
| WHERE parent_id is null | |
| UNION ALL | |
| SELECT i.id, i.parent_path, tree.ancestors || i.parent_id | |
| FROM core.items i, tree | |
| WHERE i.parent_id = tree.id | |
| ) | |
| update core.items i | |
| set parent_path = array_to_string(array_prepend('root', ancestors::text[]), '.')::ltree | |
| from tree | |
| where tree.id = i.id; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment