title: Postgresql remove values from foreign key that has a cyclic reference and also is referenced in a primary table
body: <p>There are 2 tables:</p>
  
  <p>the first one is the <strong>Father Table</strong></p>
  
  <pre><code>create table win_folder_principal(
      id_folder_principal serial primary key not null,
      folder_name varchar(300)not null
  );
  </code></pre>
  
  <p>and the table that has a cyclic reference</p>
  
  <pre><code>create table win_folder_dependency(
      id_folder_dependency serial primary key not null,
      id_folder_father int not null,
      id_folder_son int not null,
      foreign key(id_folder_father)references win_folder_principal(id_folder_principal),
      foreign key(id_folder_son)references win_folder_principal(id_folder_principal)
  );
  </code></pre>
  
  <p>however i found a very interesting situation, if i wanna remove a value from the table father that has a kid and that kid has more kids, is there any way to remove the values from the last to the first but also those values be removed from the Father table?</p>
  
  <pre><code>**WIN_FOLDER_PRINCIPAL**
   | Id | Folder_Name|
   | 23 | new2       | 
   | 24 | new3       |
   | 13 | new0       |
   | 22 | new1       |
   | 12 | nFol       |
  </code></pre>
  
  <p>And this are the value stored in the <strong>Win_Folder_Dependency</strong></p>
  
  <pre><code>**WIN_FOLDER_DEPENDENCY**
   | Id_Father | Id_Son |
   |     12    |  13    | 
   |     13    |  22    |
   |     22    |  23    |
   |     23    |  24    |
  </code></pre>
  
  <p>and this is the query that i use to know the values in the dependency and principal table.</p>
  
  <pre><code>SELECT m2.id_folder_principal AS "Principal",
           m.folder_name  AS "Dependency",
           m2.id_folder_principal AS id_principal,
           m.id_folder_principal  AS id_dependency
    FROM ((win_folder_dependency md
        JOIN win_folder_principal m ON ((m.id_folder_principal = md.id_folder_son)))
        JOIN win_folder_principal m2 ON ((m2.id_folder_principal = md.id_folder_father)))
  </code></pre>
  
  <p>If i wanna remove the folder with the <strong>Id_Principal 13</strong> i need to remove the other relations that exists in the <strong>Folder_Dependency</strong> table, but also remove the value from the <strong>Folder_Principal</strong></p>
  
  <p>is there any way to achieve that cyclic delete?</p>