anything that looks like WORDS(, , , ...) that goes
where SQL expressions go you can do with func. just use
func.DISTINCT(col1, col2).
On Fri, Dec 14, 2018 at 10:47 PM Pavel Pristupa wrote:
>
> I wonder if there's a way to build up the following SQL query for PostgreSQL
> in SQLAlchemy using
I wonder if there's a way to build up the following SQL query for
PostgreSQL in SQLAlchemy using Session.query():
SELECT group_id, COUNT(DISTINCT(column1, column2)) FROM entities GROUP BY
group_id;
I tried this one:
Session.query(Entity.group_id, sa.func.count(sa.distinct(Entity.column1,
On 11/07/2016 02:50 AM, James Burke wrote:
Thanks Mike for your response.
The query is run against a staging db and the table only contains some
500 records.
But I will check the query as you have suggested to see what is going on.
Well since it's just count() causing the problem here,
Thanks Mike for your response.
The query is run against a staging db and the table only contains some 500
records.
But I will check the query as you have suggested to see what is going on.
Cheers
>
>
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
On 11/04/2016 04:13 AM, James Burke wrote:
Hi All,
I've run into a odd problem, where calling the count function hangs my
code indefinitely. The odd thing is it was working until recently, so
I'm a little confused.
|
customer
>
>
>
Thanks for your reply Simon.
- I am using Postgresql database
- Running the SQL generated by SQL Alchemy in Postgres also hangs.
- There is no traceback.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please
On Fri, Nov 4, 2016 at 8:13 AM, James Burke wrote:
> Hi All,
>
> I've run into a odd problem, where calling the count function hangs my code
> indefinitely. The odd thing is it was working until recently, so I'm a
> little confused.
>
> customer =
>
Hi All,
I've run into a odd problem, where calling the count function hangs my code
indefinitely. The odd thing is it was working until recently, so I'm a
little confused.
customer = session.query(Customer).filter(Customer.phone_number.contains([
message['metadata']['MIN']]))
Hello,
I am trying to translate this SQL to a SQLAlchemy query, but failed so far:
select `users`.`name`, `assignments`.`id`,
(
select count(*)
from `assignments`
where `assignments`.`user_id` = `users`.`id`
) as `num_assignments`
from `users`
join `assignments`
on
it's a scalar subquery. you want to make the select() and then call
as_scalar() on it so that it behaves like a column in a SQL expression.
On Jun 24, 2013, at 9:34 AM, Sebastian Elsner sebast...@risefx.com wrote:
Hello,
I am trying to translate this SQL to a SQLAlchemy query, but failed
Hm I'm lost. This is where I am now:
session.query(User.id, Assignment.id,
session.query(func.count(Assignment.id)).filter(Assignment.user_id ==
User.id).as_scalar()).join(Assignment).all()
On 06/24/2013 04:26 PM, Michael Bayer wrote:
it's a scalar subquery. you want to make the
you might want to call correlate(User) on that scalar subquery also.
paste the SQL along with it on the next email.
On Jun 24, 2013, at 1:15 PM, Sebastian Elsner sebast...@risefx.com wrote:
Hm I'm lost. This is where I am now:
session.query(User.id, Assignment.id,
What's the recommended way to count the rows in a table. In SQL, I would
typically use select count(*) from table;
The statement session.query(table).count() issues a count(*) on a sub-query.
The docs say for finer control to use func.count
i.e. session.query(func.count(table.column)). That
Hi everybody,
After switching from SQLAlchemy 0.6.5 to 0.7.0 we have observed a
problem with such an example code:
(copy at http://ideone.com/WB36Y)
==
# Fails with Python-2.7.1 and SQLAlchemy-0.7.0
#
import sqlalchemy
import
On Jun 7, 2011, at 8:57 AM, Filip Zyzniewski - Tefnet wrote:
# this line:
print BillGates.subordinates.count()
# raises:
# Traceback (most recent call last):
# File count_problem.py, line 60, in module
# print BillGates.subordinates.count()
# File
You should use func.count(expression) instead of query.count().
On Nov 23, 2010, at 1:52 PM, Juan Antonio Ibáñez juanito1...@gmail.com wrote:
Hello
I am joining one table with itself so I am using alias as:
alias_usuarios1 = aliased(Usuario)
Hello
I am joining one table with itself so I am using alias as:
alias_usuarios1 = aliased(Usuario)
alias_usuarios2 = aliased(Usuario)
usuarios = DBSession.query(alias_usuarios1,
alias_usuarios2.nombre).filter(alias_usuarios1.resellers_id ==
alias_usuarios2.id)
Hi,
Ok, I am doing a standard tags thingee which is many-to-many. I want
to to a query so that I get the main records which have all the named
keywords. To use webpage paging efficiently, I need to get a count()
of the records. This does not seem to work the way I am doing it.
Also, I don't
Hello,
I've created a single table inheritance hierarchy where SpecialThing
inherits from BasicThing.
When I session.query(BasicThing).count() the correct count is returned,
but session.query(SpecialThing).count() returns the count for
BasicThing. In other words, when issuing .count() the 'WHERE
DB = sqlite
I don't now if this is a bug or an issue with my mapper config, but
the count() method does not work correctly through relationships.
Given this mapper:
mapper(Branch, branches, properties={
'reports':dynamic_loader(Report, backref='branch')
})
b = sess.query(Branch).first()
Hi,
I found that if I do
select([func.count(table.c.column)],distinct=True).execute()
the resulting query is
select distinct count(column) from table
but it's not what I wanted. If my column has duplicates you got
counting them, rather then count unique names. The proper SQL query
would be
Hi,
does anyone know the syntax of
SELECT COUNT(*) FROM table_name;
for SQLAlchemy? Is there a list of functions (used in SELECT statement)
that exist in SQL that I can use in SQLAlchemy? btw, I am using MySQL.
I need to see if my table is empty (isemty function doesn't work).
Thanks!
Hello,
I would like to query a big table and display the information. But at
the top of the list I'm going to display, I need a little counter that
tell how many items where returned.
What would be the most efficient way to count the results ?
client_list = session.query(Client).select()
23 matches
Mail list logo