Last active
February 14, 2020 14:50
-
-
Save lkmill/22d6b089fabb211008658168619696aa to your computer and use it in GitHub Desktop.
ancestor_topics
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
delete from links_topics where (link_id, topic_id) in ( | |
select | |
j_parent.link_id, | |
j_parent.topic_id | |
from ( | |
select | |
lt.link_id, | |
lt.topic_id, | |
t.path | |
from links_topics as lt | |
inner join topics as t on lt.topic_id = t.id | |
) as j_child | |
inner join ( | |
select | |
lt.link_id, | |
lt.topic_id, | |
t.path | |
from links_topics as lt | |
inner join topics as t on lt.topic_id = t.id | |
) as j_parent on j_parent.link_id = j_child.link_id and j_parent.path @> subpath(j_child.path, 0, nlevel(j_child.path) - 1) | |
); | |
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
select | |
j_parent.link_id, | |
j_parent.topic_id as parent_path, | |
j_parent.path as parent_path, | |
j_child.topic_id as child_path, | |
j_child.path as child_path | |
from ( | |
select | |
lt.link_id, | |
lt.topic_id, | |
t.path | |
from links_topics as lt | |
inner join topics as t on lt.topic_id = t.id | |
) as j_child | |
inner join ( | |
select | |
lt.link_id, | |
lt.topic_id, | |
t.path | |
from links_topics as lt | |
inner join topics as t on lt.topic_id = t.id | |
) as j_parent on j_parent.link_id = j_child.link_id and j_parent.path @> subpath(j_child.path, 0, nlevel(j_child.path) - 1); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment