add remove split language chart show hidden hide
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
version
PostgreSQL 14.10 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-20), 64-bit
SELECT 1
CREATE TABLE
CREATE INDEX
INSERT 0 4
id name parent_id
3 Test3 null
1 Test1 3
2 Test2 1
4 Test4 2
SELECT 4
parent_id name child_id path level
3 Test3 null 3 1
1 Test1 3 3->1 2
2 Test2 1 3->1->2 3
4 Test4 2 3->1->2->4 4
SELECT 4
INSERT 0 6
parent_id name child_id path level
3 Test3 null 3 1
1 Test1 3 3->1 2
2 Test2 1 3->1->2 3
4 Test4 2 3->1->2->4 4
5 Test5 4 3->1->2->4->5 5
6 Test6 5 3->1->2->4->5->6 6
7 Test7 6 3->1->2->4->5->6->7 7
8 Test8 7 3->1->2->4->5->6->7->8 8
9 Test9 8 3->1->2->4->5->6->7->8->9 9
10 Test10 9 3->1->2->4->5->6->7->8->9->10 10
SELECT 10
INSERT 0 1
UPDATE 1
parent_id name child_id path level
3 Test3 null 3 1
1 Test1 3 3->1 2
2 Test2 1 3->1->2 3
4 Test4 2 3->1->2->4 4
5 Test5 4 3->1->2->4->5 5
6 Test6 5 3->1->2->4->5->6 6
7 Test7 6 3->1->2->4->5->6->7 7
35 Test35 7 3->1->2->4->5->6->7->35 8
8 Test8 35 3->1->2->4->5->6->7->35->8 9
9 Test9 8 3->1->2->4->5->6->7->35->8->9 10
10 Test10 9 3->1->2->4->5->6->7->35->8->9->10 11
SELECT 11
ERROR:  new row for relation "organization" violates check constraint "parent_not_self"
DETAIL:  Failing row contains (40, Test40, 40).
INSERT 0 2
UPDATE 1
ERROR:  duplicate key value violates unique constraint "organization_not__mirrored"
DETAIL:  Key (LEAST(id, parent_id), GREATEST(id, parent_id))=(50, 51) already exists.