Hi there,
I'm looking for a little help using MySQL functions in a WHERE clause
with SQLAlchemy.
The query I'd like to do is something like "SELECT * FROM x WHERE
YEAR(FROM_UNIXTIME(timestamp)) == '2006';"
Here's how I've tried to implement it:
metadata = MetaData()
articles_table = Table('blog_articles', metadata,
Column('id', Integer, primary_key = True),
Column('timestamp', Integer),
Column('section_id', Integer, ForeignKey('blog_sections.id')),
Column('title', String(255)),
Column('text', TEXT)
)
class Article(object):
def __init__(self, timestamp, title, text):
self.article_timestamp = timestamp
self.article_title = title
self.article_text = text
mapper(Article, articles_table)
db = create_engine(settings.db_string)
session = create_session(bind_to=db)
result =
session.query(Article).select(func.year(func.from_unixtime(Article.c.timestamp))=='2006')
This throws the following error:
"(ProgrammingError) function from_unixtime(integer) does not exist
HINT: No function matches the given name and argument types. You may
need to add explicit type casts."
I tried a few things to explicitly cast the row type, but nothing
seemed to work.
This:
session.query(Article).select(func.year(func.from_unixtime(cast(Article.c.timestamp,
DateTime)))=='2006')
threw the following error:
"(ProgrammingError) cannot cast type integer to timestamp with time
zone)"
Any suggestions?
Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---