To partially clarify and answer my own question here (I was very tired by the time I pasted this last night)

In the case of:

sa .insert (mytable ).values(myothertable.select().filter_by(foo=sa.bindparam("bar"))

This doesn't currently work because the bindparam required for the select statement gets discarded. Having gone through the way SA compiles statements, it appears that parameters are used to fill in an insert statements values. The only way I can see of getting around this is that at the time of adding the values, they bindparams are extracted from the select and added to a new attribute on the insert statement, and around the time of creating the ExecutionContext, they are processed and added back into the query.

My previous question about getting both the column names and the bindparams, I managed to solve by (duh!) getting the column names, compiling the select statement and then getting the bindparams. I would still be interested to know where the bindparams are stored in an uncompiled select though. I couldn't work it out.

Sorry if all this is a little fuzzy. It's my first time at really trying to understand what SA does behind the scenes.

Thanks

Ed


On 11 Feb 2010, at 22:23, Ed Singleton wrote:

I've been having a clumsy hack at enabling myself to pass a select statement as a value to an insert statement. IE: sa.insert(mytable).values(myothertable.select())

I've got it working in that most basic case, but I'm struggling when the select statement has bindparams. The insert needs to take them, as well as (for some dialects) the column names of the select. The thing is I can work out how to get the bindparams from a compiled statement, and I can work out how to get the column names from a uncompiled statement, but I can't work out how to get both from one or the other. Any hints on this would be appreciated.

Also, I slightly worried that there's an obvious reason why this hasn't been done before. Is there something stupid I'm missing? If anyone's tried patching SA to do this I would greatly appreciate any advice.

Thanks

Ed

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to