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
Primary key issue when copying a table by Drag&Drop #23163
Comments
Author Name: Reinhard Reiterer (Reinhard Reiterer)
|
Author Name: Sandro Santilli (@strk) Reinhard can you help me reproduce the issue ? Where should I drag the table from ? Where should I drag it to ? Which versions did you test ? Can you provide SQL to initialize such example test table ? |
Author Name: Sandro Santilli (@strk) I've tried dragging the qgis_test.base_table_good table (part of testsuite in qgis_test database) into a new schema and it worked fine with 2.16 branch (2.16.3), 2.14 branch (2.14.7) and master_2 branch (2.17).
|
Author Name: Reinhard Reiterer (Reinhard Reiterer) Hi Sandro, I've uploaded a screencast. Unfortunately, I've no idea how to reproduce this issue.
|
Author Name: Sandro Santilli (@strk) Interesting, can you inspect the two tables (the one which works and the one which doesn't) with the "psql" command-line database tool ? Can it be the "gid" field is really encoded differently ? Or, can you reproduce after dumping and reloading that table ? Can you spot any other difference between the two tables ? Does it always happen on that table, no matter the order in which you copy them ? |
Author Name: Reinhard Reiterer (Reinhard Reiterer) Here comes a sample database. Please let me know if this is helpful for locating the issue.
|
Author Name: Sandro Santilli (@strk) Yes, I can reproduce with the table you provided. And not with other tables. I'm on it.
|
Author Name: Sandro Santilli (@strk) Jurgen, once again this issue is about properly defining semantic for some fields. |
Author Name: Jürgen Fischer (@jef-n) Sandro Santilli wrote:
the postgres provider handles quoted and unquoted content from keyColumn() - dbmanager should do too. |
Author Name: Sandro Santilli (@strk) On further research, I found that we get quoted identifiers in the url when the primary key type is a FidMap. This happens for multi-column keys or for non-integer keys. In both these cases, even with QGIS 2.14, we get quoted attributes in the QgsDatasourceUri keyColumn() return. In all these cases, the DBManager drag & drop operation results in a target table having quotes in the key column names. I'll see how DBManager should deal with quotes, but given the above I guess the only sane way to deal with quotes would be knowing if the quotes were added or were part of the actual field name, so somehow the "FidMap" nature should be exposed. BTW, I'm not sure it's DBManager or the provider's "CreateEmptyLayer" being responsible of parsing the URL. |
Author Name: Sandro Santilli (@strk) I confirm it should be createEmptyTable, within the Postgres provider, to interpret the URI. |
Author Name: Sandro Santilli (@strk) So with PR #3599 I've made PostgreSQL layer importer (createEmptyLayer) support quoted identifiers in Datasource URI -- for backward compatibility with projects created #21737 was fixed (that ticket lacks a target version) -- and I've reverted the commit which did add quoted identifiers in Datasource URI as they do seem redundant and inconsistent (I did test that #21737 isn't back). In its current state, the code in the PR not only fixes this bug but also adds support for Drag&Dropp'ing tables with multi-column keys (including those with mixed-cased-colum names) |
Author Name: Sandro Santilli (@strk)
|
Author Name: Reinhard Reiterer (Reinhard Reiterer) Sandro, it's great to see this bug fixed. Sandro Santilli wrote:
As seen in screencast '15226_screencast.wmv' copying tables by D&D may also fail. Is there anything else to do? |
Author Name: Sandro Santilli (@strk) Fixed in changeset "5abdfcb8064f3b3a848358afb95723b932dd3b05".
|
Author Name: Sandro Santilli (@strk)
|
Author Name: Reinhard Reiterer (Reinhard Reiterer)
Original Redmine Issue: 15226
Affected QGIS version: 2.16.3
Redmine category:db_manager
Assignee: Sandro Santilli
When copying a table (PostGIS) in the 'DB Manager' by D&D, the name of the primary key is placed in quotes (e.g. "gid"). As a result, there is a "gid" and a gid column in the new table.
The text was updated successfully, but these errors were encountered: