-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
qgspostgresprovider choosing non-unique column as primary key #11595
Comments
Author Name: jcs - (jcs -) after a little more code diving... the above case will be caught by uniqueData() if and only if the tables are initialized before the layer is created. if in a dynamic situation where the tables are initialized after the layer is created, the error condition still exists. i still think a better resolution is to catch the join and rule out any of those columns as you cannot be sure they will not one day become non-unique. |
Author Name: jcs - (jcs -) My attached bugfix allows the user to specify which column they would like to use as the primary key by filling out the added "key" data member of the [[QgsDataSourceURI]]. The [[QgsPostgresProvider]] will do some verification on the specified column if it exists, otherwise it will do the current method of trying to find a column to use. |
Author Name: gjm - (gjm -) I think that we also need to provide this sort of UI functionality:
In both cases, qgis should continue to check that the column contains unique data. |
Author Name: jcs - (jcs -) Replying to [comment:6 jef]:
in my situation, i am using the qgis library and neither the application directly nor a project file. also, the problem i was having was preventing me from loading the layer initially. it would seem, then, that it would never make it into the project file? |
Author Name: Jürgen Fischer (@jef-n) Replying to [comment:7 jcs]:
Right. The original problem is probably still there. AFAICS your patch doesn't address that issue either. So I didn't close the bug.
setDataSourceUri( mUri.uri() );
|
Author Name: jcs - (jcs -) Replying to [comment:8 jef]:
That's correct, I gave up on the bug and took the easy way out :). Something tells me that no matter what algorithm is used to look for a unique column, a view could be constructed that breaks it. That's just my pessimistic hunch, I have no proof.
|
Author Name: Paolo Cavallini (@pcav) Can this be considered a solution to the problem? Should the ticket be left open, or can be closed? |
Author Name: jcs - (jcs -) Replying to [comment:10 pcav]:
|
Author Name: Jürgen Fischer (@jef-n) Replying to [comment:11 jcs]:
Ok then.
|
Author Name: jcs - (jcs -)
Original Redmine Issue: 1535
Redmine category:data_provider
Assignee: Jürgen Fischer
Table A (rid primary key, bid int, loc geometry)
Table B (rid primary key, id2 unique)
View V is (select Table.rid, Table B.id2, Table A.loc from Table A left outer join Table B on Table A.bid=Table B.rid;)
The problem is Qgis may select Table B.id2 as its primary key because of the unique constraint in the table definition even though V.id2 is not constrained to be unique in the view.
For example if Table A has
rid | bid | loc
1 | 1 | POINTA
2 | 2 | POINTB
3 | 1 | POINTC
and Table B has
rid | id2
1 | 47
2 | 48
View V would have
rid | id2 | loc
1 | 47 | POINTA
2 | 48 | POINTB
3 | 47 | POINTC
Resolution... columns obtained through a left outer join should not be included for consideration as a primary key... this could be implemented by a modification to findColumns() in qgspostgresprovider to not return such columns.
The text was updated successfully, but these errors were encountered: