Hello, I came across this while I was building an experimental project to get to grips with sqlalchemy. I wanted to only set some fields when inserting rows, but wanted to decouple the code that actually built the SQL from the decision logic, which led me to pass column references, which led me here. I was passing column objects as the decision logic was reused in other code that used the referenced column in statement building.
I doubt that this is a particularly common use case, nor is it a major problem and it was the inconsistency that threw me more than anything. It could be avoided by pulling out the key attribute from the column objects prior to building the insert statements, although this seems like it would be needlessly inconsistent with the rest of sqlalchemy and I suspect would eventually surprise other people, especially given the inconsistency in the function call itself. I couldn't find any document for using column objects for insert and hence I thought I'd ask here before sending a PR. Cheers, Aubrey > a little frustrating because I've checked the documentation again and > nowhere can I find it documenting the use case of sending column > objects as keys to values() for an INSERT; but for UPDATE there are. > > Yet, there are tests that do test the use case of using column objects > as keys in the context of INSERT. the ORM uses strictly column keys > for INSERT but in a few spots does use the column object as key in the > case of an UPDATE. > > The reason columns as objects make a little more sense for UPDATE is > because some databases do actually allow for a SQL expression that is > more than just a simple column to be established as the left side of > the SET clause (like Postgresql JSON assignment), but no such > equivalent exists on the INSERT side. > > Nevertheless, it seems like a use case that should work across the > board but I'm kind of curious how you came up with it, if this is > actually documented somewhere I'm not seeing, or if documentation > showing columns as keys came from the UPDATE use case which naturally > seems like it should fit for INSERT too. I unfortunately have to > make sure not only that all the documented use cases are covered but > also all the naturally occurring, non-documented use cases, like this > one, also work, so I seek to understand better how people come up with > these cases. > > TL;DR sure please supply a PR for the execute multiple case, thanks! > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
