Skip to content

Conversation

@Mytherin
Copy link
Contributor

@Mytherin Mytherin commented Aug 7, 2025

Implements #189
Implements #278
Implements #309

This PR adds support for the MERGE INTO / ON CONFLICT clauses to the Postgres scanner, e.g. this now works:

D ATTACH 'postgres:dbname=postgresscanner' AS pgdb;
D CREATE OR REPLACE TABLE pgdb.my_tbl(id INTEGER PRIMARY KEY, val VARCHAR);
D INSERT INTO pgdb.my_tbl VALUES (42, 'hello');
D INSERT OR REPLACE INTO pgdb.my_tbl VALUES (42, 'world');
D FROM pgdb.my_tbl;
┌───────┬─────────┐
│  id   │   val   │
│ int32 │ varchar │
├───────┼─────────┤
│  42   │ world   │
└───────┴─────────┘
D INSERT INTO pgdb.my_tbl VALUES (42, 'hello again') ON CONFLICT DO UPDATE SET val=excluded.val;
D FROM pgdb.my_tbl;
┌───────┬─────────────┐
│  id   │     val     │
│ int32 │   varchar   │
├───────┼─────────────┤
│  42   │ hello again │
└───────┴─────────────┘
MERGE INTO pgdb.my_tbl USING (VALUES (42, 'world again'), (43, 'new world')) t(id, val) USING (id)
  WHEN MATCHED THEN UPDATE
  WHEN NOT MATCHED THEN INSERT;
D FROM pgdb.my_tbl;
┌───────┬─────────────┐
│  id   │     val     │
│ int32 │   varchar   │
├───────┼─────────────┤
│    43 │ new world   │
│    42 │ world again │
└───────┴─────────────┘

@karthik-isw
Copy link

Thanks a lot.

@dineshmarimu2
Copy link

dineshmarimu2 commented Oct 9, 2025

@Mytherin Which version of duckdb has this upsert feature postgres server implemented? I don't see the milestone in the issue populated. Nor is there any documentation in the postgres extension that explicitly state that this upsert is possible with postgres.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants