-
-
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
PostgreSQL identity column not recognized properly #29560
Comments
Author Name: Michal Zimmermann (Michal Zimmermann) Jürgen Fischer wrote:
How do I tell which QGIS version will include this fix? |
Writing to identity column works in v 3.8.0, yet it seems a bit hackish to me. Even though the database column is defined as
which overrides the value generated by the database itself. I'd say the proper solution to this would be to respect the |
@andywicht can you elaborate? I'm on 3.10.2 and I can add feature to a table that as PK like the following: The gid has the NOT NULL constraint, but also is SERIAL so it gets autofilled. If you don't have the serial property is up to you to add a proper value for the pk column. |
@gioman I have to correct my statement. CREATE SCHEMA test;
CREATE TABLE test.test (
gid int8 NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
geom geometry(polygon)
);
INSERT INTO test.test (geom)
VALUES ('POLYGON EMPTY'::geometry);
SELECT *
FROM test.test;
gid|geom
---|-------------
1|POLYGON EMPTY Then QGIS does not understand that the DB will autogenerate a value and one would see the window as it can be seen in the previous screenshot. You can actually put in an ID manually, which defeats the purpose of an autogenerated ID. When defining the primary key as "SERIAL" (default value incrementing the sequence) everything works as expected. Ignore the fact that I wrote you cannot input anything (I think I tried to add characters but the datatype forbids that. So that's fine). |
Fixes qgis#29560 - PostgreSQL identity column not recognized properly
Fixes qgis#29560 - PostgreSQL identity column not recognized properly
Works on 3.22.4. Have you also define that fpd_uid is primary key? |
I ran in to an issue by setting both a bigint as identity and having a second primary key of a uuid. QGIS wouldn't get the bigint primary key from the DB. When removed the uuid as a primary key and only had the bigint as primary key, QGIS would allow a feature to be created and get the nextval from the DB. |
I'm still (or again?) having the same problem on QGIS 3.22.10 with the column "id int8 NOT NULL GENERATED ALWAYS AS IDENTITY" defined as primary key. |
I think I figured it out now: the problem only exists when the option 'Evaluate default values on provider side' (Project Properties / Data Sources Properties) is activated. Without it, everything works just fine... |
Author Name: Michal Zimmermann (Michal Zimmermann)
Original Redmine Issue: 21745
Affected QGIS version: 3.6.1
Redmine category:data_provider/postgis
Having the following table definition:
features cannot be added to QGIS, because the Feature Attributes dialogue requires id column to be not null. However, when any value is filled, the saving fails with the following error:
According to https://blog.2ndquadrant.com/postgresql-10-identity-columns/, the syntax of identity columns in PostgreSQL conforms to the SQL standard and it's been around for a while.
The text was updated successfully, but these errors were encountered: