pg-mem icon indicating copy to clipboard operation
pg-mem copied to clipboard

ON CONFLICT <target> does not work when <target> is ON CONSTRAINT

Open seanlindo opened this issue 3 years ago • 1 comments

Describe the bug

According to the documentation, the following is valid syntax:

INSERT INTO test (person_id, person_skill)
VALUES('abc', 'programming')
ON CONFLICT ON CONSTRAINT uniq_skill DO UPDATE
SET modified_at = now()

Error

💔 Your query failed to parse.
    This is most likely due to a SQL syntax error. However, you might also have hit a bug, or an unimplemented feature of pg-mem.
    If this is the case, please file an issue at https://github.com/oguimbal/pg-mem along with a query that reproduces this syntax error.

    👉 Failed query:

        insert into "test"("person_id","person_skill") values('abc','programming')
                ON CONFLICT ON CONSTRAINT uniq_skill DO UPDATE
                    SET modified_at = now()
            ;

    💀 Syntax error at line 2 col 25:

                  ON CONFLICT ON
                              ^
    Unexpected kw_on token: "on". Instead, I was expecting to see one of the following:

        - A "kw_do" token
        - A "lparen" token
        - A "kw_do" token

To Reproduce


CREATE TABLE test(
    id SERIAL PRIMARY KEY,
    person_id text NOT NULL,
    person_skill text NOT NULL,
    created_at timestamp with time zone DEFAULT now(),
    modified_at timestamp with time zone DEFAULT now()
);

ALTER TABLE test ADD CONSTRAINT uniq_skill  UNIQUE (person_id, person_skill);

INSERT INTO test (person_id, person_skill)
            VALUES
                ('abc', 'tcp/ip'),
                ('abc', 'programming');

INSERT INTO test (person_id, person_skill)
VALUES('abc', 'programming')
ON CONFLICT ON CONSTRAINT uniq_skill DO UPDATE
SET modified_at = now()

pg-mem version

2.3.5

seanlindo avatar Apr 15 '22 16:04 seanlindo

Hitting the same issue

gregorymfoster avatar Apr 26 '22 18:04 gregorymfoster

Fixed in [email protected] ! Sorry for the delay

oguimbal avatar Mar 02 '23 11:03 oguimbal