I have two Postgresql tables: parent and child, as the following:
CREATE SEQUENCE public.parent_id_seq; CREATE TABLE public.parent ( id integer NOT NULL DEFAULT nextval('public.parent_id_seq'::regclass), type character varying COLLATE pg_catalog."default", CONSTRAINT parent_pkey PRIMARY KEY (id) ); CREATE SEQUENCE public.child_id_seq; CREATE TABLE public.child ( id integer NOT NULL DEFAULT nextval('public.child_id_seq'::regclass), name character varying COLLATE pg_catalog."default", parent_id integer, CONSTRAINT child_pkey PRIMARY KEY (id), CONSTRAINT child_parent_id_fkey FOREIGN KEY (parent_id) REFERENCES public.parent (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION );
In QGIS I have made a join between these two tables (as shown in the attached image). But I am not able to add new features from the attribute table. When I do so I got the following error:
Could not commit changes to layer child Errors: ERROR: 1 feature(s) not added. Provider errors: PostGIS error while adding features: ERROR: invalid input syntax for integer: "nextval('public.parent_id_seq'::regclass)" LINE 1: ...ild"("id","name","parent_id") VALUES ($1,'name 9','nextval('...
How to Reproduce
1- Create these two tables, as described above.
2- Add them to QGIS.
3- Right click on the parent table, then select properties, then from the Joins tab create a new Join as shown in the attached screen shot.
4- Then allow editing both layers.
5- After that open the attribute table of the parent layer, then select Add Feature, and fill in the type and name fields.
6- Save the parent layer, it will be saved with no problems. Then save the child layer, it will generate the error mentioned above.
I am using QGIS 3.10
parent_idare swapped. The sequence should populate
$1should be the
$1is the value of the
child_id_sequence. When the parent table is saved, another (maybe
$1) value is stored in the
parent.idfield, but the child table don't know it and try to store the default
nextval('public.parent_id_seq'::regclass)value in its