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

Dynamic on conflict definition #1025

Open
olmohake opened this issue Jan 31, 2025 · 0 comments
Open

Dynamic on conflict definition #1025

olmohake opened this issue Jan 31, 2025 · 0 comments

Comments

@olmohake
Copy link

I am struggling to set up the SET part of my on conflict definition dynamically.
Everything else working smoothly, but failing to pass upsert information.
Would welcome any help.

const targetTable = "test"
const columns = ["id", "name", "geometry"]
const onConflict = { keys: ["id"], update: ["name", "geometry"]}

await sql`
  INSERT INTO ${sql(targetTable)} ${sql(data, columns)}
  ON CONFLICT (${sql(onConflict.keys.join(","))}) DO UPDATE
  SET ${sql(onConflict.update.map(column => `${column} = EXCLUDED.${column}`).join(",")};
`
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

No branches or pull requests

1 participant