SqlAlchemy filter_by with kwargs containing listsSQLAlchemy IN clauseDynamically constructing filters in SQLAlchemyHow do I check if a list is empty?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How to make a flat list out of list of listsHow do I concatenate two lists in Python?How to clone or copy a list?How do I list all files of a directory?How to read a file line-by-line into a list?Use of *args and **kwargsDoes Python have a string 'contains' substring method?
How would a disabled person earn their living in a medieval-type town?
Can authors email you PDFs of their textbook for free?
Am I required to correct my opponent's assumptions about my morph creatures?
Why are CEOs generally fired rather being demoted?
An alternative to "two column" geometry proofs
Understanding GFCI configuration in basement
How are the cards determined in an incomplete deck of many things?
Correct way of simplifying the result of an integral
How does Query decide the order in which the functions are applied?
Why do fuses burn at a specific current?
Why is Mitch McConnell blocking nominees to the Federal Election Commission?
Why wasn't Linda Hamilton in T3?
Polarity of gas discharge tubes?
How could reincarnation magic be limited to prevent overuse?
How does the search space affect the speed of an ILP solver?
Why is this reversed StringBuilder not equal to the original String, when it is a palindrome?
Received email from ISP saying one of my devices has malware
How were US credit cards verified in-store in the 1980's?
Is the equational theory of groups axiomatized by the associative law?
New coworker has strange workplace requirements - how should I deal with them?
Should we run PBKDF2 for every plaintext to be protected or should we run PBKDF2 only once?
Underbrace in equation
What happens if you just start drawing from the Deck of Many Things without declaring any number of cards?
How to solve this inequality , when there is a irrational power?
SqlAlchemy filter_by with kwargs containing lists
SQLAlchemy IN clauseDynamically constructing filters in SQLAlchemyHow do I check if a list is empty?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How to make a flat list out of list of listsHow do I concatenate two lists in Python?How to clone or copy a list?How do I list all files of a directory?How to read a file line-by-line into a list?Use of *args and **kwargsDoes Python have a string 'contains' substring method?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to build a filter statement from kwargs
that may contain lists as values:
def delete_object(self, from_table, filters, commit=True):
(self._session
.query(from_table)
.filter_by(**filters)
.delete(synchronize_session=False))
The filters
contain keys which represent columns in the table and values that are supposed to be filtered.
If the values are not lists
'id': 1, 'name': 'test'
then it works fine. However, when the values are lists
'id': [3]
then the resulting sql statement that is created looks like this
DELETE FROM <table> WHERE <table>.id = ARRAY[3]
Is there a way to handle list elements as well?
python sqlalchemy
add a comment |
I'm trying to build a filter statement from kwargs
that may contain lists as values:
def delete_object(self, from_table, filters, commit=True):
(self._session
.query(from_table)
.filter_by(**filters)
.delete(synchronize_session=False))
The filters
contain keys which represent columns in the table and values that are supposed to be filtered.
If the values are not lists
'id': 1, 'name': 'test'
then it works fine. However, when the values are lists
'id': [3]
then the resulting sql statement that is created looks like this
DELETE FROM <table> WHERE <table>.id = ARRAY[3]
Is there a way to handle list elements as well?
python sqlalchemy
What about unpacking the list and loop? I'm not sure if SQLAlchemy has that level of robust to be able to parse your kwargs of different data objects
– kerwei
Mar 28 at 1:53
Yes that's an option but for lists with 100+ entries that's a lot of queries
– wasp256
Mar 28 at 2:53
No it wouldn't be creating individual queries for each item in the list, it would dynamically create a filter for each object in the list and then apply all the filters to a single query. See this answer: stackoverflow.com/a/14887813/6560549 for something similar.
– SuperShoot
Mar 28 at 3:01
add a comment |
I'm trying to build a filter statement from kwargs
that may contain lists as values:
def delete_object(self, from_table, filters, commit=True):
(self._session
.query(from_table)
.filter_by(**filters)
.delete(synchronize_session=False))
The filters
contain keys which represent columns in the table and values that are supposed to be filtered.
If the values are not lists
'id': 1, 'name': 'test'
then it works fine. However, when the values are lists
'id': [3]
then the resulting sql statement that is created looks like this
DELETE FROM <table> WHERE <table>.id = ARRAY[3]
Is there a way to handle list elements as well?
python sqlalchemy
I'm trying to build a filter statement from kwargs
that may contain lists as values:
def delete_object(self, from_table, filters, commit=True):
(self._session
.query(from_table)
.filter_by(**filters)
.delete(synchronize_session=False))
The filters
contain keys which represent columns in the table and values that are supposed to be filtered.
If the values are not lists
'id': 1, 'name': 'test'
then it works fine. However, when the values are lists
'id': [3]
then the resulting sql statement that is created looks like this
DELETE FROM <table> WHERE <table>.id = ARRAY[3]
Is there a way to handle list elements as well?
python sqlalchemy
python sqlalchemy
asked Mar 28 at 0:30
wasp256wasp256
2,2024 gold badges35 silver badges72 bronze badges
2,2024 gold badges35 silver badges72 bronze badges
What about unpacking the list and loop? I'm not sure if SQLAlchemy has that level of robust to be able to parse your kwargs of different data objects
– kerwei
Mar 28 at 1:53
Yes that's an option but for lists with 100+ entries that's a lot of queries
– wasp256
Mar 28 at 2:53
No it wouldn't be creating individual queries for each item in the list, it would dynamically create a filter for each object in the list and then apply all the filters to a single query. See this answer: stackoverflow.com/a/14887813/6560549 for something similar.
– SuperShoot
Mar 28 at 3:01
add a comment |
What about unpacking the list and loop? I'm not sure if SQLAlchemy has that level of robust to be able to parse your kwargs of different data objects
– kerwei
Mar 28 at 1:53
Yes that's an option but for lists with 100+ entries that's a lot of queries
– wasp256
Mar 28 at 2:53
No it wouldn't be creating individual queries for each item in the list, it would dynamically create a filter for each object in the list and then apply all the filters to a single query. See this answer: stackoverflow.com/a/14887813/6560549 for something similar.
– SuperShoot
Mar 28 at 3:01
What about unpacking the list and loop? I'm not sure if SQLAlchemy has that level of robust to be able to parse your kwargs of different data objects
– kerwei
Mar 28 at 1:53
What about unpacking the list and loop? I'm not sure if SQLAlchemy has that level of robust to be able to parse your kwargs of different data objects
– kerwei
Mar 28 at 1:53
Yes that's an option but for lists with 100+ entries that's a lot of queries
– wasp256
Mar 28 at 2:53
Yes that's an option but for lists with 100+ entries that's a lot of queries
– wasp256
Mar 28 at 2:53
No it wouldn't be creating individual queries for each item in the list, it would dynamically create a filter for each object in the list and then apply all the filters to a single query. See this answer: stackoverflow.com/a/14887813/6560549 for something similar.
– SuperShoot
Mar 28 at 3:01
No it wouldn't be creating individual queries for each item in the list, it would dynamically create a filter for each object in the list and then apply all the filters to a single query. See this answer: stackoverflow.com/a/14887813/6560549 for something similar.
– SuperShoot
Mar 28 at 3:01
add a comment |
1 Answer
1
active
oldest
votes
It looks like this answer may be able to help:
SQLAlchemy IN clause
Summing is up, you can us _in
, like so:
session.query(MyUserClass)
.filter(MyUserClass.id.in_(SOME_LIST)).all()
Yes I know about thein_
but that does not really relate to my code since it takes away the dynamic part and me having to parse all kwargs manually...
– wasp256
Mar 28 at 0:38
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55388463%2fsqlalchemy-filter-by-with-kwargs-containing-lists%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It looks like this answer may be able to help:
SQLAlchemy IN clause
Summing is up, you can us _in
, like so:
session.query(MyUserClass)
.filter(MyUserClass.id.in_(SOME_LIST)).all()
Yes I know about thein_
but that does not really relate to my code since it takes away the dynamic part and me having to parse all kwargs manually...
– wasp256
Mar 28 at 0:38
add a comment |
It looks like this answer may be able to help:
SQLAlchemy IN clause
Summing is up, you can us _in
, like so:
session.query(MyUserClass)
.filter(MyUserClass.id.in_(SOME_LIST)).all()
Yes I know about thein_
but that does not really relate to my code since it takes away the dynamic part and me having to parse all kwargs manually...
– wasp256
Mar 28 at 0:38
add a comment |
It looks like this answer may be able to help:
SQLAlchemy IN clause
Summing is up, you can us _in
, like so:
session.query(MyUserClass)
.filter(MyUserClass.id.in_(SOME_LIST)).all()
It looks like this answer may be able to help:
SQLAlchemy IN clause
Summing is up, you can us _in
, like so:
session.query(MyUserClass)
.filter(MyUserClass.id.in_(SOME_LIST)).all()
answered Mar 28 at 0:34
Matthew Salvatore ViglioneMatthew Salvatore Viglione
6652 silver badges21 bronze badges
6652 silver badges21 bronze badges
Yes I know about thein_
but that does not really relate to my code since it takes away the dynamic part and me having to parse all kwargs manually...
– wasp256
Mar 28 at 0:38
add a comment |
Yes I know about thein_
but that does not really relate to my code since it takes away the dynamic part and me having to parse all kwargs manually...
– wasp256
Mar 28 at 0:38
Yes I know about the
in_
but that does not really relate to my code since it takes away the dynamic part and me having to parse all kwargs manually...– wasp256
Mar 28 at 0:38
Yes I know about the
in_
but that does not really relate to my code since it takes away the dynamic part and me having to parse all kwargs manually...– wasp256
Mar 28 at 0:38
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55388463%2fsqlalchemy-filter-by-with-kwargs-containing-lists%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What about unpacking the list and loop? I'm not sure if SQLAlchemy has that level of robust to be able to parse your kwargs of different data objects
– kerwei
Mar 28 at 1:53
Yes that's an option but for lists with 100+ entries that's a lot of queries
– wasp256
Mar 28 at 2:53
No it wouldn't be creating individual queries for each item in the list, it would dynamically create a filter for each object in the list and then apply all the filters to a single query. See this answer: stackoverflow.com/a/14887813/6560549 for something similar.
– SuperShoot
Mar 28 at 3:01