Re: [sqlalchemy] Conditional Insertion of Single Row with Bind Parameters

2022-03-24 Thread mkmo...@gmail.com
Hi Mike, Thanks, `literal` is good. Regarding the `insert_where` function, would you mind providing some feedback on the API? I'm writing a library that uses SQLAlchemy so I would like this API to be relatively consistent with the SQLAlchemy approach. So far I have been doing it like the

Re: [sqlalchemy] Conditional Insertion of Single Row with Bind Parameters

2022-03-23 Thread Mike Bayer
On Tue, Mar 22, 2022, at 2:46 PM, mkmo...@gmail.com wrote: > I would like to do a conditional insert of a a single row. This is often > useful in a CRUD app for checking permissions and inserting in a single > database call: > > INSERT INTO project (name, user_id) > SELECT :name, :user_id >

[sqlalchemy] Conditional Insertion of Single Row with Bind Parameters

2022-03-22 Thread mkmo...@gmail.com
I would like to do a conditional insert of a a single row. This is often useful in a CRUD app for checking permissions and inserting in a single database call: INSERT INTO project (name, user_id) SELECT :name, :user_id WHERE EXISTS ( SELECT 1 FROM users WHERE id = :user_id