Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Codidact Meta!

Codidact Meta is the meta-discussion site for the Codidact community network and the Codidact software. Whether you have bug reports or feature requests, support questions or rule discussions that touch the whole network – this is the site for you.

Comments on Remove parent tags from a post where a child tag is present

Post

Remove parent tags from a post where a child tag is present

+1
−2

With the hierarchical tags, it would be possible to have both a tag and its parent on the same post which is means that the parent tag is unneeded. An example would be a post with both an animal and a deer tag on Outdoors.

Rather than manually removing the parent tags from these posts, it should be possible to do it with a SQL statement.

If I understand the schema right, this should select posts where this happens,

SELECT post_id 
FROM posts_tags pt1
JOIN tags t1 on pt1.tag_id = t1.id
JOIN tags t2 on t1.id = t2.parent_id
JOIN post_tags pt2 on pt1.post_id = pt2.post_id and pt2.tag_id = t2.id

To remove the relationships, simply replace the select with

DELETE pt1

assuming the SQL is correct.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

General comments (4 comments)
General comments
ArtOfCode‭ wrote over 4 years ago · edited over 4 years ago

Is this a one-time request for existing posts, or a request for this to happen automatically for all new questions?

Charlie Brumbaugh‭ wrote over 4 years ago

@Artofcode To me this would be ongoing, to me the point of hierarchical tags was to remove the need to ever tag a post with both the parent and the child tags.

ArtOfCode‭ wrote over 4 years ago

@CharlieBrumbaugh In that case, I think I agree with msh210's answer - it seems that there are cases where both tags could apply. Let's see what others think. As an alternative, it might be possible to add a warning - check the tags before posting the question, and alert the author if both a parent and a child tag are in use.

pnuts‭ wrote about 4 years ago

If asking for automatic removal of parent where child is present and if editing in a parent where child is present seems odd?