Skip to content
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

Unable to use upsert when joining two PostGIS tables #38300

Open
m-kuhn opened this issue Aug 15, 2020 · 3 comments
Open

Unable to use upsert when joining two PostGIS tables #38300

m-kuhn opened this issue Aug 15, 2020 · 3 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! PostGIS data provider

Comments

@m-kuhn
Copy link
Member

m-kuhn commented Aug 15, 2020

I have two tables for which I added a join and used the upsert option.

One table zones and one table status. For each zone, there must be a status defined. Usually, features will be added on zones and corresponding statuses need to be created.

When I add a new zone, it tries to insert a new status indeed, but fails because the id of it is NULL. It seems not to be taking the primary key for the new status from the database serial.

Looking at #33148 which looks very, very similar but it's actually inverted. There, the user starts with the "parent" table and joins a "child" (analogue here: add a status and upsert a zone).

From what I understand, currently the default value needs to be defined on the "main" table field (zones.status_id) while in most of the scenarios I can come up with, the opposite would be the case.

The documentation is silent on default value handling for upsert joins, so I wonder if this requirement here would rather be a new feature than a bug.

CREATE SEQUENCE public.zone_id_seq;

CREATE TABLE public.zones
(
    id integer NOT NULL DEFAULT nextval('public.zone_id_seq'::regclass),
    type character varying,
    status_id integer,
    CONSTRAINT zone_pkey PRIMARY KEY (id)
    CONSTRAINT zone_status_id_fkey FOREIGN KEY (status_id)
        REFERENCES public.status (id) MATCH SIMPLE
);

CREATE SEQUENCE public.status_id_seq;

CREATE TABLE public.status
(
    id integer NOT NULL DEFAULT nextval('public.status_id_seq'::regclass),
    name character varying,

    CONSTRAINT status_pkey PRIMARY KEY (id),
);
@m-kuhn m-kuhn added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Aug 15, 2020
@Pedro-Murteira
Copy link

@m-kuhn Hello, is this issue still valid on recent releases?

@Pedro-Murteira Pedro-Murteira added the Feedback Waiting on the submitter for answers label Apr 21, 2022
@m-kuhn
Copy link
Member Author

m-kuhn commented Apr 21, 2022

Pretty sure, yes

@Pedro-Murteira Pedro-Murteira removed the Feedback Waiting on the submitter for answers label Apr 21, 2022
@alexbruy
Copy link
Contributor

Another similar issue #34239

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! PostGIS data provider
Projects
None yet
Development

No branches or pull requests

4 participants