Scalar subquery in limit clause

I need to run a query like this:
table1.select(limit=(table2.select(Count(table2.id))))
When I do this I get AssertionError message.
Is it possible to use a scalar subquery in limit clause?

The SQL standard allows only literal constant, a parameter, or a variable name so python-sql allows only integer.
The usage of sub-query is an extension of PostgreSQL.

Solved the problem this way:

    query1 = table1.select(limit=0)
    query2 = table2.select(Count(table2.id))

    query = ("%s" % query1).replace("LIMIT 0", "LIMIT (%s)" % query2)

    cursor = Transaction().connection.cursor()
    cursor.execute(query)

Of course, DBMS must support the usage of scalar sub-queries.

It is way simpler and more portable to run the first query and put the result as limit of the second.

Oh sure. Thanks a lot.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.