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

Postgres ON CONFLICT DO NOTHING #583

Closed
Boscop opened this Issue Jan 20, 2017 · 5 comments

Comments

Projects
None yet
5 participants
@Boscop

Boscop commented Jan 20, 2017

How can I do something like:

INSERT INTO tags (name) values ('foo'), ('bar'), ('baz') ON CONFLICT DO NOTHING;

with diesel with postgres as backend.
Basically I want to insert all except the ones that are already in the table.
Without ON CONFLICT DO NOTHING it would unroll and not insert any if one is already in the table.

@killercup

This comment has been minimized.

Member

killercup commented Jan 20, 2017

@sgrif worked on supporting UPSERT in November (ON CONFLICT DO UPDATE), which turned out to be pretty tricky.

Do you expect to get a return value with all the skipped rows?

@Boscop

This comment has been minimized.

Boscop commented Jan 20, 2017

Not necessary. I just want to make sure that all tags are in the table after the query.
So I can get all their ids with the next query.

@sgrif

This comment has been minimized.

Member

sgrif commented Feb 2, 2017

Duplicate of #196

@sgrif sgrif closed this Feb 2, 2017

@emk

This comment has been minimized.

Contributor

emk commented Feb 7, 2017

We just ran into a case where we need this for our production application using a mix of diesel's PostgreSQL backend and some postgres. I'm probably going to have to roll back the diesel conversion of several tables that I just did. :-/

How much work would it be for me to implement this?

@Eijebong

This comment has been minimized.

Member

Eijebong commented Feb 7, 2017

@emk If you really need this, you can use custom psql functions with sql_function!

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