Bug report #19657

QGIS3: unable to turn off PK creation (export to PostgreSQL)

Added by Tobias Wendorff almost 2 years ago. Updated almost 2 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Processing/Core
Affected QGIS version:3.2.1 Regression?:No
Operating System:Microsoft Windows 7, 64-bit Easy fix?:No
Pull Request or Patch supplied:No Resolution:invalid
Crashes QGIS or corrupts data:No Copied to github as #:27482

Description

My dataset has the field "id", which contains duplicates. When using "DB-Manager" or "Processing", an error occurs that there are duplicates in this field. The reason for this: "id" always gets used for a PK and there's no way to turn it off. This makes impossible to export the data to PGSQL.

Workaround: Create a new auto-incremental column and use this as PK.
Bugfix: Create a switch to turn off index creation (like for GiST) or allow to add a new fid with auto-incremental on server-side.

This affects all QGIS versions >= 3.1 (and maybe earlier).


Related issues

Related to QGIS Application - Bug report #19667: Processing "import into PostGIS" does not allow to choose... Open 2018-08-22

History

#1 Updated by Giovanni Manghi almost 2 years ago

  • Resolution set to invalid
  • Status changed from Open to Closed

If you are using DB Manager to import a vector in PostGIS then yes, he uses "id" as a default column for the PK. If the column already exist and has duplicates then the error you see is expected. What you should do is to enable the checkbox beside "primary key" and select a different column name (for the PK): such column will be automatically created (with a serial datatype) while importing and populated.

A similar thing happens when using Processing.

#2 Updated by Tobias Wendorff almost 2 years ago

Giovanni Manghi wrote:

If you are using DB Manager to import a vector in PostGIS then yes, he uses "id" as a default column for the PK. If the column already exist and has duplicates then the error you see is expected. What you should do is to enable the checkbox beside "primary key" and select a different column name (for the PK): such column will be automatically created (with a serial datatype) while importing and populated.

Ah! I assumed that you can specify which field you want to use as a PK. So better not use "oid", "fid" and "id" as a PK, since there's a high possibility that this columns already exist. It's pretty much trial-and-error :-(

#3 Updated by Tobias Wendorff almost 2 years ago

Hey, you can't enter a new name in "Processing" - it's select only! This issue needs to be re-opened. "DB-Manager" seems to work like you described it.

#4 Updated by Giovanni Manghi almost 2 years ago

Tobias Wendorff wrote:

Hey, you can't enter a new name in "Processing" - it's select only! This issue needs to be re-opened. "DB-Manager" seems to work like you described it.

#19667

#5 Updated by Jürgen Fischer almost 2 years ago

  • Related to Bug report #19667: Processing "import into PostGIS" does not allow to choose an arbitrary name for the (new) column that will be defined as primary key added

Also available in: Atom PDF