<div dir="ltr">Currently Pony doesn't have have support for "upserts". The main problem lies in PostgreSQL - it is technically impossible to implement "create or update" correctly in PostgreSQL, and any possible solution has at least one problem - possible deadlock, race condition, lost update, etc.<br>
<a href="http://www.depesz.com/2012/06/10/why-is-upsert-so-complicated/">http://www.depesz.com/2012/06/10/why-is-upsert-so-complicated/</a><br>Because of this is is not clear to me how database-independent API for "create or update" command should look in Pony.<br>
<br>The StackOverflow answer that you mention give an SQL example of "INSERT ... ON DUPLICATE UPDATE" for MySQL. Currently you can execute such command in Pony using raw SQL. For example you can use Database.execute() method, something like this:<br>
<br> pk_value = 123 # this is the value of primary key<br> increment = 1 # I want to update other column with this value<br> db.execute("""<br> INSERT INTO MyTable (pk_column, other_column) VALUES($pk_value, $increment)<br>
ON DUPLICATE KEY UPDATE other_column = other_column + VALUES(other_column)<br> """)<br><br><br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Aug 27, 2014 at 5:28 AM, Jake Austwick <span dir="ltr"><<a href="mailto:jake.austwick@gmail.com" target="_blank">jake.austwick@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>Does Pony have functionality to create or update if existing a model in one query, or do I have to check with exists() first?</div><div><br></div><div>Example: <a href="http://stackoverflow.com/a/1218909/2175384" target="_blank">http://stackoverflow.com/a/1218909/2175384</a></div>
<div><br></div><div>I couldn't find a way to do this in one query in the documentation, and if it currently isn't in there, is it a planned feature?</div><div><br></div><div>Thanks,</div><span class="HOEnZb"><font color="#888888"><div>
<div>-- </div><div>Jake Austwick</div><div></div><div></div></div>
</font></span><br>_______________________________________________<br>
ponyorm-list mailing list<br>
<a href="mailto:ponyorm-list@ponyorm.org">ponyorm-list@ponyorm.org</a><br>
<a href="/ponyorm-list" target="_blank">/ponyorm-list</a><br>
<br></blockquote></div><br></div>