Updates using ResultSet

Hi list,

I am using PostgreSQL. In the database I have a view with a join over two tables:

CREATE OR REPLACE VIEW test_view AS

SELECT a.pid, b.dia

FROM lab.stammdaten a

JOIN lab.dia b USING (pid)

Now when I want to update (field dia) the resultset obtained from the view, I get the following error message:

java.sql.SQLException: No primary key foundfor table ((lab.stammdaten.

at com.edb.jdbc2.AbstractJdbc2ResultSet.isUpdateable(AbstractJdbc2ResultSet.java:1539)

at com.edb.jdbc2.AbstractJdbc2ResultSet.checkUpdateable(AbstractJdbc2ResultSet.java:2393)

at com.edb.jdbc2.AbstractJdbc2ResultSet.updateValue(AbstractJdbc2ResultSet.java:2643)

at com.edb.jdbc2.AbstractJdbc2ResultSet.updateInt(AbstractJdbc2ResultSet.java:1108)

at de.unir.gui4db.ui.event.DBTableFrameListener.actionPerformed(DBTableFrameListener.java:188)

Of course I have a primary key in both tables...

I'm thankful for any suggestions.

[1030 byte] By [abenstexa] at [2007-11-27 11:02:43]
# 1

BTW I do not call the view using.

SELECT * FROM test_view, but instead I call the view definition.

abenstexa at 2007-7-29 12:45:10 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Yes, but views don't have a primary key - you can't update a row unless you can uniquely identify it, and since the view's metadata won't contain any primary key information there's no way for the driver to determine that it's save to use the id column as a key when using an updateable result set.

dcmintera at 2007-7-29 12:45:10 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

I suppose as an alternative to adding a primary key to the view and trying to update the view, you would be better off updating the tables directly (that make up that view). Also, put the updates in a transaction.

George123a at 2007-7-29 12:45:10 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

Besides, surely you have to write the insert rule for an updateable PostgreSQL view...?

dcmintera at 2007-7-29 12:45:10 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...