Re: [sqlalchemy] replacing a filter attribute, or iterating over a booleanclauselist?

2016-03-02 Thread Brian Cherinka
Also, I've noticed that when you update the bindparams q = q.params(x='1234') and then try to print the whereclause, the parameters are not updated. Yet in the statement, they are updated. print q.query.whereclause.compile(dialect=postgresql.dialect(),compile_kwargs={'literal_binds':True})

Re: [sqlalchemy] replacing a filter attribute, or iterating over a booleanclauselist?

2016-03-02 Thread Brian Cherinka
> > > > well you need a list of names so from a mapped class you can get: > > for name in inspect(MyClass).column_attrs.keys(): > if name in : > q = q.filter_by(name = bindparam(name)) > > though I'd think if you're dynamically building the query you'd have the > values already,

Re: [sqlalchemy] replacing a filter attribute, or iterating over a booleanclauselist?

2016-03-02 Thread Mike Bayer
On 03/02/2016 04:59 PM, Brian Cherinka wrote: Thanks, Mike. This is excellent. That did the trick. That's much easier than what I was trying to do. Do you know if there is a way to auto bindparam every parameter I have in my Declarative Bases, if and when they get added into a filter?

Re: [sqlalchemy] replacing a filter attribute, or iterating over a booleanclauselist?

2016-03-02 Thread Brian Cherinka
I'm essentially building a tool for a group that doesn't know SQLalchemy, and doesn't want to know or care about it, or even SQL in general. They need to be able to query a dataset using minimal input, namely only caring about the input filter conditions (e.g. X > 10). Presumably, they will

Re: [sqlalchemy] replacing a filter attribute, or iterating over a booleanclauselist?

2016-03-02 Thread Brian Cherinka
I'm essentially building a tool for a large group of people that don't know SQLalchemy, and will never care enough or want to know, about SQLalchemy or SQL in general. And they need to be able to build queries to the dataset based on really minimal information. All they would input are

Re: [sqlalchemy] replacing a filter attribute, or iterating over a booleanclauselist?

2016-03-02 Thread Simon King
Out of interest, how are you building your query, and why do you need to be able to change the values afterwards? Simon > On 2 Mar 2016, at 21:59, Brian Cherinka wrote: > > Thanks, Mike. This is excellent. That did the trick. That's much easier > than what I was

Re: [sqlalchemy] replacing a filter attribute, or iterating over a booleanclauselist?

2016-03-02 Thread Brian Cherinka
Thanks, Mike. This is excellent. That did the trick. That's much easier than what I was trying to do. Do you know if there is a way to auto bindparam every parameter I have in my Declarative Bases, if and when they get added into a filter? Basically, I need to allow the user to be able to

Re: [sqlalchemy] replacing a filter attribute, or iterating over a booleanclauselist?

2016-03-02 Thread Mike Bayer
On 03/02/2016 03:29 PM, Brian Cherinka wrote: Hi, After a query has been constructed with some filter conditions applied, but before the query has been run, what's the best way to replace the attribute in the filter clause? Let's say I have a query like this | q

[sqlalchemy] replacing a filter attribute, or iterating over a booleanclauselist?

2016-03-02 Thread Brian Cherinka
Hi, After a query has been constructed with some filter conditions applied, but before the query has been run, what's the best way to replace the attribute in the filter clause? Let's say I have a query like this q = session.query(Cube).join(Version).filter(Version.version == 'v1_5_1') and

Re: [sqlalchemy] Date range query problem

2016-03-02 Thread Jonathan Vanasco
Just FYI, there is a small edge-case in that approach if the db stores time with microseconds. If that's the case, you may be better off comparing to a 'floored" date column, or using a search where you grab values ">=" the start and "<" the end. Otherwise you'll miss values that happen

Re: [sqlalchemy] Date range query problem

2016-03-02 Thread Nana Okyere
Thanks. I added a time part to the datetime.datetime object as: end_dt = datetime.datetime.combine(pd.Timestamp(form.to_dt.data).to_datetime(), datetime.time(23,59,59)) Then I passed end_dt to the query. it works great. -- You received this message because you are subscribed to the Google

Re: [sqlalchemy] need help with query

2016-03-02 Thread Simon King
I don't understand that error - you're asking it to join along predefined relationships, so it shouldn't need to search for foreign keys at query time. "Category.products" is a relationship set up as the backref of Product.categories. Here's a working example. I had to add the definition of the