![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, i have a table with the columns id, pid, nodetext which represent a tree. Root elements are signed by providing NULL for pid, i.e. 1 NULL Root1 2 1 ChildOfRoot1 Now i want to force the nodetext to be unique within a certain pid. So i created an UNIQUE CONSTRAINT covering the mentioned fields. CONSTRAINT tbl_T_uc UNIQUE (pid, nodetext) This works for all nodes having a pid != null. But it is still possible to insert duplicate root nodes having pid == null. I've read the pg docs and found that this behavior of unique constraints is wantet. So, is it possible to force the desired behavior by still using unique constraints or do i have to use triggers or something else? |
#3
| |||
| |||
|
|
Hi, i have a table with the columns id, pid, nodetext which represent a tree. Root elements are signed by providing NULL for pid, i.e. 1 NULL Root1 2 1 ChildOfRoot1 Now i want to force the nodetext to be unique within a certain pid. So i created an UNIQUE CONSTRAINT covering the mentioned fields. CONSTRAINT tbl_T_uc UNIQUE (pid, nodetext) This works for all nodes having a pid != null. But it is still possible to insert duplicate root nodes having pid == null. I've read the pg docs and found that this behavior of unique constraints is wantet. So, is it possible to force the desired behavior by still using unique constraints or do i have to use triggers or something else? |
#4
| |||
| |||
|
|
Hi, i have a table with the columns id, pid, nodetext which represent a tree. Root elements are signed by providing NULL for pid, i.e. 1 NULL Root1 2 1 ChildOfRoot1 Now i want to force the nodetext to be unique within a certain pid. So i created an UNIQUE CONSTRAINT covering the mentioned fields. CONSTRAINT tbl_T_uc UNIQUE (pid, nodetext) This works for all nodes having a pid != null. But it is still possible to insert duplicate root nodes having pid == null. I've read the pg docs and found that this behavior of unique constraints is wantet. So, is it possible to force the desired behavior by still using unique constraints or do i have to use triggers or something else? |
#5
| |||
| |||
|
|
Hi, i have a table with the columns id, pid, nodetext which represent a tree. Root elements are signed by providing NULL for pid, i.e. 1 NULL Root1 2 1 ChildOfRoot1 Now i want to force the nodetext to be unique within a certain pid. So i created an UNIQUE CONSTRAINT covering the mentioned fields. CONSTRAINT tbl_T_uc UNIQUE (pid, nodetext) This works for all nodes having a pid != null. But it is still possible to insert duplicate root nodes having pid == null. I've read the pg docs and found that this behavior of unique constraints is wantet. So, is it possible to force the desired behavior by still using unique constraints or do i have to use triggers or something else? |
#6
| |||
| |||
|
|
Hi, i have a table with the columns id, pid, nodetext which represent a tree. Root elements are signed by providing NULL for pid, i.e. 1 NULL Root1 2 1 ChildOfRoot1 Now i want to force the nodetext to be unique within a certain pid. So i created an UNIQUE CONSTRAINT covering the mentioned fields. CONSTRAINT tbl_T_uc UNIQUE (pid, nodetext) This works for all nodes having a pid != null. But it is still possible to insert duplicate root nodes having pid == null. I've read the pg docs and found that this behavior of unique constraints is wantet. So, is it possible to force the desired behavior by still using unique constraints or do i have to use triggers or something else? |
#7
| |||
| |||
|
|
Hi, i have a table with the columns id, pid, nodetext which represent a tree. Root elements are signed by providing NULL for pid, i.e. 1 NULL Root1 2 1 ChildOfRoot1 Now i want to force the nodetext to be unique within a certain pid. So i created an UNIQUE CONSTRAINT covering the mentioned fields. CONSTRAINT tbl_T_uc UNIQUE (pid, nodetext) This works for all nodes having a pid != null. But it is still possible to insert duplicate root nodes having pid == null. I've read the pg docs and found that this behavior of unique constraints is wantet. So, is it possible to force the desired behavior by still using unique constraints or do i have to use triggers or something else? |
#8
| |||
| |||
|
|
Hi, i have a table with the columns id, pid, nodetext which represent a tree. Root elements are signed by providing NULL for pid, i.e. 1 NULL Root1 2 1 ChildOfRoot1 Now i want to force the nodetext to be unique within a certain pid. So i created an UNIQUE CONSTRAINT covering the mentioned fields. CONSTRAINT tbl_T_uc UNIQUE (pid, nodetext) This works for all nodes having a pid != null. But it is still possible to insert duplicate root nodes having pid == null. I've read the pg docs and found that this behavior of unique constraints is wantet. So, is it possible to force the desired behavior by still using unique constraints or do i have to use triggers or something else? |
#9
| |||
| |||
|
|
Hi, i have a table with the columns id, pid, nodetext which represent a tree. Root elements are signed by providing NULL for pid, i.e. 1 NULL Root1 2 1 ChildOfRoot1 Now i want to force the nodetext to be unique within a certain pid. So i created an UNIQUE CONSTRAINT covering the mentioned fields. CONSTRAINT tbl_T_uc UNIQUE (pid, nodetext) This works for all nodes having a pid != null. But it is still possible to insert duplicate root nodes having pid == null. I've read the pg docs and found that this behavior of unique constraints is wantet. So, is it possible to force the desired behavior by still using unique constraints or do i have to use triggers or something else? |
#10
| |||
| |||
|
|
test=*# create unique index idx_node on node(coalesce(pid,-1),t); As you can see, you can insert distinct values for the text-field and NULL in the pid, but no with NULL in the pid and the same text. Helps that? |
![]() |
| Thread Tools | |
| Display Modes | |
| |