problem with updateable view and constraint - Mailing list pgsql-general

From Oleg
Subject problem with updateable view and constraint
Date
Msg-id 432ED7F5.5000702@iwk.uka.de
Whole thread Raw
Responses deactivating/activating constraint
List pgsql-general
Dear All
I am
PostgreSQL beginner. I am trying to write some values from external
source
table “Table1” (using PostGIS plugin) to 2 destination PostgreSQL
tables
“Table2” and “Table3” that describes relations of data:
<span lang="EN-GB"
 style="font-family: "Courier New";">Table1:
| A | B |
---------
| 1 | 1 |
| 2 | 3 |
| 3 | 1 |
<span lang="EN-GB"
 style="font-family: "Courier New";">
Table2
| C |
-----
| 1 |
| 2 |


<span lang="EN-GB"
 style="font-family: "Courier New";">Table3
| D | E |
---------
| 1 | 1 | case 1
| 2 | 3 | case
2
<span lang="EN-GB"
 style="font-family: "Courier New";">
Table3 has
constraint:
FOREIGN KEY
E REFERENCES Table2 (C) ON UPDATE NO ACTION ON DELETE RESTRICT;


I use
updateable view “View1” (due to PostGIS interface) with columns “C” and
“E” and
rule:
AS ON
INSERT TO View1 DO INSTEAD (INSERT INTO Table2 VALUES (NEW.C); INSERT
INTO
Table3 VALUES (NEW.D, NEW.E));


<span lang="EN-GB"
 style="font-size: 12pt; font-family: "Times New Roman";">I faced
following problem: As it is shown in Table3
while trying to write data in case 1 everything works fine, but case 2
is not
possible due to constraint in Table3. However my aim is to write a
column A to
column C, column A to column D and column B to column E not removing
constraint
for table3. May be there is a way to adjust constraint? Or may be to
adjust rule somehow to make it to write all data from column A to
column C first and after that fill in Table3?
Thanks a lot in advance
Oleg

pgsql-general by date:

Previous
From: Alex Turner
Date:
Subject: Arrrr... date formatting.
Next
From: "Stas Oskin"
Date:
Subject: Blob data type and it's efficiency on PostgreSQL