Sergey Nuzhdin

1 minute read

Short sqlalchemy query to get highcharts ready data from database from datetime field.

select count(1), extract(epoch from date_trunc('hour', created_at)) from bid group by extract(epoch from date_trunc('hour', created_at));
    db.session
        .query(
            extract('epoch', func.DATE(Bid.created_at)).label('dt'),
            func.count()
        )
        .filter(Bid.ownership == o)
        .filter(Bid.created_at > days_to_count )
        .group_by('dt')
        .order_by('dt')
    )

Like this post? Want more? Subscribe to get updates delivered straight to your inbox.
comments powered by Disqus