Am Donnerstag, 7. Februar 2019 23:45:09 UTC+1 schrieb Mike Bayer:
>
>
>
> note the mentioned issue is closed. IN supports an inline parameter now:
>
> https://docs.sqlalchemy.org/en/rel_1_2/orm/extensions/baked.html#baked-in
>
>
We had started using the .op('IN') approach around v1.1 and I hadn't
realized that SQLAlchemy supports this now. Very good to know, thanks.
I have integrated your suggested approach with the 'before_cursor_execute'
rewrite of the statement, and it works nicely, thanks again!
Simply out of curiosity and because I'm trying to understand the internals
a bit better:
1) Theoretically, would another possible approach be to implement a
sub-class of BindParameter (let's say PGValuesBindParameter) and - in
combination with the .op('IN') approach - overwrite the bind-parameter
behavior so it passes the values as one long string like this:
.filter(Item.parent_id.op('IN')(PGValuesBindParameter('parent_ids')))
# Parameters that are passed into the statement:
{
'parent_ids': "(VALUES ('abc'), ('def'), ('gjh'))"
}
2) I've also considered using the following construct with the
array-function from the postgres-dialect. It achieves the same performance
improvement as the VALUES approach and doesn't require the tricky rewriting
of the VALUES-part with the inner parentheses:
func.unnest(array(parent_ids))
but I couldn't get it to work with bindparams (tried also with
expanding=True).
Which one would you suggest/do you think is the cleanest... the VALUES
statement-rewrite, or one of those other approaches?
--
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.