Hi,
Is there perhaps a bug in the sqlalchemy function lower (func.lower)? I'm
trying to do a simple query that filters on a string keyword (the label of
a header_keyword). I want to bind the parameter so I can easily update the
label after the fact, and I want to use the func.lower to ensure no funny
stuff, and all lowercase. Without using the lower everything works fine,
and when I print the query, the correct variables are inserted into the
query. However, it seems when I use func.lower, the bindparam no longer
works and inserts NULL into the variable. Any ideas what I'm doing wrong?
Is there a proper way to write this such that it works? Thanks.
*Without Lower*
In [59]: tmpq=session.query(Cube).join(HeaderValue,HeaderKeyword).filter(
HeaderKeyword.label==bindparam('header_keyword.label', 'PLATE'))
In [55]: print tmpq
SELECT cube.*
FROM cube JOIN header_value ON cube.pk = header_value.cube_pk JOIN
header_keyword ON header_keyword.pk = header_value.header_keyword_pk
WHERE header_keyword.label = %(header_keyword.label)s
In [56]: print tmpq.statement.compile(compile_kwargs={'literal_binds':True})
SELECT cube.*
FROM cube JOIN header_value ON cube.pk = header_value.cube_pk JOIN
header_keyword ON header_keyword.pk = header_value.header_keyword_pk
WHERE header_keyword.label = 'PLATE'
*With Lower*
In [59]: tmpq=session.query(Cube).join(HeaderValue,HeaderKeyword).filter(
func.lower(HeaderKeyword.label)==bindparam('header_keyword.label',func.lower
('PLATE')))
In [60]: print tmpq
SELECT cube.*
FROM cube JOIN header_value ON cube.pk = header_value.cube_pk JOIN
header_keyword ON header_keyword.pk = header_value.header_keyword_pk
WHERE lower(header_keyword.label) = %(header_keyword.label)s
In [61]: print tmpq.statement.compile(compile_kwargs={'literal_binds':True})
SELECT cube.*
FROM cube JOIN header_value ON cube.pk = header_value.cube_pk JOIN
header_keyword ON header_keyword.pk = header_value.header_keyword_pk
WHERE lower(header_keyword.label) = NULL
--
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.