Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResultSet should be updateable when using a Unique Key instead of a Primary Key (null columns) #2196

Closed
2 tasks done
chalmagr opened this issue Jun 28, 2021 · 9 comments
Closed
2 tasks done

Comments

@chalmagr
Copy link

I'm submitting a ...

  • bug report
  • feature request

Describe the issue
When attempting to update a table which has Unique Key (but not Primary Key due to nullable columns) using the ResultSet the Missing primary key exception is thrown. Unique keys should be accounted for as well as Primary Keys when marking a ResultSet as updateable or not.

Driver Version?
42.2.20

Java Version?
Adopt OpenJDK 11.0.10+9

OS Version?
MacOS / BigSur

PostgreSQL Version?
12.7 (Docker Image postgresql:12.7)

To Reproduce
Create a ResultSet from a table with only unique key and attempt to update the row when selecting all columns from the unique key

Expected behaviour
It should be allowed and it should work as if it were a Primary Key

Logs
NA

@davecramer
Copy link
Member

This will introduce some performance issues, as we now have to fetch unique keys as well. Is there documentation in the API to support this ?

@chalmagr
Copy link
Author

chalmagr commented Jul 1, 2021

There is no restriction on the API of ResultSet that require the PK of the table to allow updateRow to be called (JDK 11 Reference

In other methods there are references to java.sql.RowId which would probably help removing such requirement.

We have been using Oracle Database and we had no such restrictions there to perform the changes to the Row. We have been always accessing a Table object and not any View or similar that would prevent the RowId from being truly available in the ResultSet - I would assume this restriction still holds true. Now while moving into Postgres, it is making the journey somewhat bumpy because of this - wouldn't want to re-write the whole data management framework if possible... :)

@davecramer
Copy link
Member

Fair enough. I can see us extending it to Unique columns, however you should be aware that all the RowId functions are not implemented in PostgreSQL because the server does not provide a row id

@teetrenz
Copy link

teetrenz commented Aug 6, 2021

Hi,

I updated to the latest JDBC driver 42.2.23 and I am getting now an exception "org.postgresql.util.PSQLException: No primary key found for table" although my table has a id column which is a primary key. That was working with previous versions of the JDBC driver. Testing now with 42.2.22.

@teetrenz
Copy link

teetrenz commented Aug 6, 2021

Just for your information. I tried 42.2.22 and it is still working fine. 42.2.23 seems to be broken.

@davecramer
Copy link
Member

Yes, it's not as simple as I first thought. I'll be pushing a fix shortly

@chalmagr
Copy link
Author

chalmagr commented Aug 18, 2021

Created PR #2228

@ionutursuleanu
Copy link

Just for your information. I tried 42.2.22 and it is still working fine. 42.2.23 seems to be broken.

I also noticed this. 42.2.23 is unusable for me

@davecramer
Copy link
Member

fixed with #2228

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants