I have a problem with my postgres database. I have a table Tasks with 3 columns: ID, Name and Parent_ID (which refers to another task id in this table):
id | name | parent_id
---+------+-----------
1 | A | 0
2 | B | 1
3 | C | 2
4 | D | 1
5 | E | 0
6 | F | 0
So basically it's like this:
1. A
2. B
3. C
4. D
5. E
6. F
What I'm trying to do is to delete task A, and delete all of its children and all children of children etc etc..(in this case B and D, along with C as its children of B which is deleted) something like cascade delete, but i cant do this. Maybe any function will work?
The result after delete should be
id | name | parent_id
---+------+-----------
5 | E | 0
6 | F | 0
Hope you guys can help me.