Re: [sqlalchemy] calling LENGTH() in SQLite?

2019-07-30 Thread Simon King
Your example is missing a bracket. I think I would expect this to work:

for position, in
session.query(Position.position).filter(func.length(Position.position)
== 2):
print(position)

If it still doesn't work, can you show the query that it's generating?

Simon

On Tue, Jul 30, 2019 at 4:53 AM James Hartley  wrote:
>
> Perhaps I have been up too many hours, but my syntax foo is fizzling.  Given 
> the following class, I want to compute the string length of "position" 
> instead of storing it as another attribute which can get out of sync.  eg.
>
> class Position(Base):
> __tablename__ = 'position'
> id = Column(INTEGER, primary_key=True)
> timestamp = Column(TIMESTAMP, nullable=False)
> position = Column(TEXT, unique=True, nullable=False)
>
> So to get all positions of string length 2, the following is not working:
> from sqlalchemy.sql.expression import func
> # ...
> for position, in 
> session.query(Position.position).filter(func.length(Position.position == 2):
> print(position)
>
> Any insight offered would certainly be appreciated.
>
> Thanks!
>
> --
> 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 sqlalchemy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/CAKeNXXtURxf-eXNaXn1woYE_q9i%3DggeopN%2B_%3D9hQb3FWfqqyLQ%40mail.gmail.com.

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CAFHwexe7316zV9zWX8MPBurX6ph354Qv%3DO426LOHK%3D1Mf2M77A%40mail.gmail.com.


[sqlalchemy] calling LENGTH() in SQLite?

2019-07-29 Thread James Hartley
Perhaps I have been up too many hours, but my syntax foo is fizzling.
Given the following class, I want to compute the string length of
"position" instead of storing it as another attribute which can get out of
sync.  eg.

class Position(Base):
__tablename__ = 'position'
id = Column(INTEGER, primary_key=True)
timestamp = Column(TIMESTAMP, nullable=False)
position = Column(TEXT, unique=True, nullable=False)

So to get all positions of string length 2, the following is not working:
from sqlalchemy.sql.expression import func
# ...
for position, in
session.query(Position.position).filter(func.length(Position.position == 2):
print(position)

Any insight offered would certainly be appreciated.

Thanks!

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CAKeNXXtURxf-eXNaXn1woYE_q9i%3DggeopN%2B_%3D9hQb3FWfqqyLQ%40mail.gmail.com.