-
-
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
Copying table by Drag&Drop in Browser (2) doesn't copy the table structure correctly #45286
Comments
I agree that this would be nice to have but I think we need to aim to a partial fix (or feature request, I'm not sure about what category this would fall into), and here is why: The current implementation of the exporter is provider-agnostic, the method receives an URI that defines the source of the export (which can be anything: a json layer, a memory layer, a DB layer etc.), some information about the original source is lost (because QGIS does not store it anywhere). What we know at that point are the fields (including some constraints like UNIQUE and NOT NULL but not much more than that) and the original QGIS layer URI (that does not include PK information because it comes from the browser). In fact, if the drag comes from the browser, we don't have a layer instance like when the drag is initiated from the TOC/legend, this means that we do not have any information regarding the PK(s) in that case what the exporter tries to do is to create a PK named A possible enhancement would be to be smarter about the presence of numeric UNIQUE/NOT NULL field ant take it as a PK candidate, this would work in simple cases and would probably partially fix this issue, it would fail in case of composite PKs. |
The more I think about it the more I think this is more a feature request than a bug and that the main misunderstanding is about That said, I agree that the layer creation for postgis layers might really be smarter and implement some PK guessing logic. |
When exporting a layer, if no PK information is passed in the destination URI, the first numeric field with NOT NULL and UNIQUE constraints is considered to be the primary key. Partial fix for qgis#45286
When exporting a layer, if no PK information is passed in the destination URI, the first numeric field with NOT NULL and UNIQUE constraints is considered to be the primary key. Partial fix for #45286
I'd say we need to be cautious here, if you don't want me to open a bug some time later that'd say "QGIS mistakenly takes my unique constraint as a PK" 😆 My take as a user: I prefer the current behaviour than a PK guess that fails even only 5% of the case. The current PK guess on
This makes sense, except for the fact QGIS fails to create a new sequence for the new id (I guess because one with the same name already exists). I really think it should not do that (and that it's a bug). What do you think? Anyway, from a user POV, the distinction between copy and export is not very. I don't have any suggestion apart from trying to make copy and export the same thing wherever possible, but maybe there could be hints in the UI (not sure how to do that though)? So yes, think it'd be nice if the datasource informations would somehow be kept, to be able to do more clever things if the datasource type is the same between source and destination for instance. I have absolutely no idea of the implication in the code though 😄 Anyway thanks for the explanation. It makes sense and helped me to better understand the logic. |
What is the bug or the crash?
When using drag and drop to copy a table to another schema in a PostGIS database, the structure of the table is incorrectly copied. There are issues with:
Steps to reproduce the issue
\d gis_data
create schema test;
test
\d test.gis_data
generated always as identity
) and created a new PK. I've also tested with serial, and while QGis did detect the PK in this case, it also fails to generate a new sequence for the new table, meaning the old and the new PKS are sharing a sequence (this will bring trouble)not null
,unique
andcheck
.Versions
Supported QGIS version
New profile
Additional context
I haven't tested triggers, but it's not clear to me what's the correct behaviour for them. I'd say it's probably better not to copy it, to be on the safe side of things. I'd argue copying any other constraints should be done though.
Thanks !
The text was updated successfully, but these errors were encountered: