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

Upsert #124

Open
cdekok opened this issue Jan 24, 2017 · 10 comments
Open

Upsert #124

cdekok opened this issue Jan 24, 2017 · 10 comments

Comments

@cdekok
Copy link

cdekok commented Jan 24, 2017

This is perhaps a bit db specific but it would be nice if there was an option for upsert in pgsql, seems there is something in mysql for it too not sure about other db's

@pmjones
Copy link
Member

pmjones commented Jan 24, 2017

I think #115 might cover that.

@harikt
Copy link
Member

harikt commented Jan 25, 2017

@pmjones that looks only for mysql. May be pgsql needs to add something similar.

@cdekok
Copy link
Author

cdekok commented Jan 25, 2017

In postgres it's
ON CONFLICT DO UPDATE or ON CONFLICT DO NOTHING
https://www.postgresql.org/docs/9.5/static/sql-insert.html

@pmjones
Copy link
Member

pmjones commented Jan 25, 2017

@cdekok Excellent -- can you post a comment on PR #115 to that effect? The contributor there might like to know.

@cdekok
Copy link
Author

cdekok commented Jan 25, 2017

@pmjones I just looked at the code but I think this is for different functionality, in mysql it would be
ON DUPLICATE https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html
replace causes a delete before insert which could cause issues: http://stackoverflow.com/a/9168948

@pavarnos
Copy link
Contributor

pavarnos commented Jan 26, 2017

ok. i wasn't aware of the implications (re the SO answer). lets abandon / delete #115 and start again with ON DUPLICATE KEY UPDATE. @cdekok do you want to make the new PR?

@cdekok
Copy link
Author

cdekok commented Jan 26, 2017

@pavarnos I could give it a shot, the one thing that would be hard is that with postgres you can specify the column or constraint on which the conflict occurs but on mysql it's always thrown on a primary key / unique index.
I don't really see how we could keep a consistent interface for them, any ideas?

@pavarnos
Copy link
Contributor

pavarnos commented Jan 26, 2017

There is already something in the sqlite driver https://github.com/auraphp/Aura.SqlQuery/blob/3.x/src/Sqlite/Insert.php
https://www.sqlite.org/lang_conflict.html
#115 aimed to use the same method signature for MySQL and sqlite so unit tests could swap drivers with no compatibility layer needed. Would be cool if we could do the same for postgres. What about a method signature like this:
function onDuplicateKey($sql = 'driver specific sql with sensible default')
?
so the default is do nothing, then

Mysql\Insert::onDuplicateKey($sql = 'ON DUPLICATE KEY UPDATE');
Sqlite\Insert::onDuplicateKey($sql ='ON CONFLICT REPLACE');
Pgsql\Insert::onDuplicateKey($sql = 'ON CONFLICT DO UPDATE');

... just thinking out loud...

@pmjones
Copy link
Member

pmjones commented Mar 22, 2017

@pavarnos Do you want to add the appropriate code to the various driver-specific classes? (FWIW, I don't think the method would need the $sql argument; just add the appropriate string literals to the build process.)

@pavarnos
Copy link
Contributor

pavarnos commented Mar 22, 2017 via email

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

4 participants