Wird behavour of foreign keys
| От | lundeman@tbkol.dk |
|---|---|
| Тема | Wird behavour of foreign keys |
| Дата | |
| Msg-id | 1071068130.3fd733e2a69ee@webmail.tbkol.dk обсуждение исходный текст |
| Ответы |
Re: Wird behavour of foreign keys
|
| Список | pgsql-general |
Hi list As I'm new to this list please kick me in the right direction if this question is better asked somewhere else. I'm seing some wird behavoure regarding foreign keys. My situation is this: I have 3 tables: pages PK: page_id page_group pk: page_group_id fk: pages(page_id) ON DELETE CASCADE, ON UPDATE NO_ACTION fk: groups(group_id) ON DELETE CASCADE, ON UPDATE NO_ACTION groups pk: group_id let's say I have the following data: pages: page_group: groups: page_id pg_id | page_id | group_id group_id 1 1 | 1 | 1 1 2 2 | 1 | 2 2 (I know this could be done more easy and the page_group table could be dropped, but I did not make the design, I'm just struggling with it) Now, if I move a group (say with id 1) from one page (page 1) to another (page 2)I do it by; UPDATE page_group set page_id=2 WHERE page_group_id=1; Now I have: pages: page_group: groups: page_id pg_id | page_id | group_id group_id 1 1 | 2 | 1 1 2 2 | 1 | 2 2 Now I have moved group 1 from page 1 to page 2. BUT if I delete page 1 then page_group 1 and 2 are both delted, and so are the two groups. This is not what I would expect, as I have moved group 1 to page 2. Is this a BUG, or is it something that I'm doing wrong. As i understand the ON UPDATE constraint on the foreignkey, it will only update the foreign key if the value which it references is changed, which is not what I'm doing. Hope someone can help me, or tell me if it's a bug or not. Because I'm going crazy here. René Jensen
В списке pgsql-general по дате отправления: