Ff00ff/mammoth

ON CONSTRAINT name cannot be a parameter token

Closed this issue · 1 comments

Example error:

42xxx error on Postgres query: INSERT INTO test (name) VALUES ($1) ON CONFLICT ON CONSTRAINT $2 DO UPDATE SET name = $3
error: syntax error at or near "$3"

Example repro:

const test = defineTable({
  id: uuid().primaryKey().default(`gen_random_uuid()`),
  name: text(),
});

const main = async () => {
  await db
    .insertInto(db.test)
    .values({ name: "martin" })
    .onConflictOnConstraint("test_pkey")
    .doUpdateSet({ name: "martin" });
};

This is fixed on master and the fix will be available in a future release.

This was unexpected though. This issue is also not documented I believe. It may be worthwhile to have some sort of end-to-end test to have these types of queries actually hitting a running instance of postgres to see if these queries are considered valid.