473,378 Members | 1,383 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Strange constraint violation when applying rules to a view.

Hello.

This section works fine:

CREATE TABLE torder (
id INT8 NOT NULL PRIMARY KEY
);

CREATE TABLE torder_row (
id INT8 NOT NULL PRIMARY KEY,
torder_id INT8 NOT NULL REFERENCES torder (id) ON DELETE RESTRICT
);

CREATE VIEW vorder(orderID, rowID) AS SELECT 1, 1 FROM torder;

CREATE RULE vorder_ins AS ON INSERT TO vorder
DO INSTEAD
(INSERT INTO torder VALUES (NEW.orderID);
INSERT INTO torder_row VALUES (NEW.rowID, NEW.orderID);
);

CREATE RULE vorder_upd AS ON UPDATE TO vorder
DO INSTEAD
(INSERT INTO torder (id) VALUES (NEW.orderID);
UPDATE torder_row SET torder_id = NEW.orderID;
DELETE FROM torder WHERE id = OLD.orderID;
);

INSERT INTO vorder VALUES (1, 1);
UPDATE vorder SET orderID = 2;
SELECT * FROM vorder;
But when I change the view to the following:

CREATE VIEW vorder(orderID, rowID) AS SELECT 1, 1 FROM torder;
becomes
CREATE VIEW vorder(orderID, rowID) AS SELECT id, 1 FROM torder;

I get the following error:
ERROR: insert or update on table "torder_row" violates foreign key
constraint "$1"

This was just a small test so the table definitions and view makes
little sense, but generally, any time the view actualy selects columns
it seems the update rule fails with a constraint violation even though
it shouldn't.

Thank's for reading!
/Peter

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #1
2 1798
I know this might be a tad early, but is there available a 7.5 Beta Win32
binary somewhere?

Thx
Glen
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #2
gl******@nwlink.com ("Glen Parker") wrote in message news:<AJEKKAIECKNMBCEKADJPEEOHCKAA.gl******@nwlink .com>...
I know this might be a tad early, but is there available a 7.5 Beta Win32
binary somewhere?


http://www.hagander.net/pgsql/win32snap/
Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Agoston Bejo | last post by:
I want to enforce such a constraint on a column that would ensure that the values be all unique, but this wouldn't apply to NULL values. (I.e. there may be more than one NULL value in the column.)...
0
by: Ron | last post by:
Mandatories: Ver 7.3.4, Redhat Linux 8.0, P4, 2GB RAM I want to add a 'nullable' foreign key to a column in a table. I have tables "company" and "project" which may be related by...
2
by: Sudip Chakraborty | last post by:
Is there a way to see constraint validation errors while loading xml into a DataSet ? I'm interested in the line number in the xml file which is causing the error. I've enclosed the relevant stack...
8
by: Ollie Riches | last post by:
I am trying to access an AD from asp.net, I am getting the 'famous' "The specified domain either does not exist or could not be contacted" exception with a HR = 0x08007054b the code (C# .Net) is...
2
by: D. Dante Lorenso | last post by:
I'm trying to build a table that will store a history of records by enumerating the records. I want the newest record to always be number ZERO, so I created a trigger on my table to handle the...
1
by: Luqman | last post by:
I have created a form using single Table which has customerId and companyName field, using Typed Dataset. Now, if I click on Delete Button of Binding Navigator, the Customer Record is deleted...
2
by: Kenneth Koenraadt | last post by:
Hi Wing, The utility Oracle offers for that is *check constraints*. For instance : ALTER TABLE Demerit ADD CONSTRAINT a1 CHECK (points between 1 and 6); ALTER TABLE Demerit ADD CONSTRAINT...
12
by: Pietro Cerutti | last post by:
Dear all, I would like to open another topic to try to clarify a doubt raised on my previous post today with the subject 'printf("%d%d%d")'. Reading through the standard, I cannot find a clear...
2
by: rorajoey | last post by:
Violation of UNIQUE KEY constraint 'IX_surveyQuestions'. Cannot insert duplicate key in object 'dbo.surveyQuestions'. This might seem like a simple matter of trying to insert a row with ID=20 when...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.