Hi there-

I see you are using str() to get the string representation, which will
not give you a MySQL representation. DId you read
https://docs.sqlalchemy.org/en/13/faq/sqlexpressions.html#how-do-i-render-sql-expressions-as-strings-possibly-with-bound-parameters-inlined
?



On Wed, May 8, 2019 at 9:31 AM Jacob Jensen <[email protected]> wrote:
>
> I'm trying to use the query API to create a MySQL query with the the 
> MAX_EXECUTION_TIME(30000) hint.
>
> My code is roughly:
>
> from flask_sqlalchemy import SQLAlchemy
>
> class MyTable(SQLAlchemy().Model):
>   ...
>
> base_query = Sqlalchemy.session.query(MyTable) # This works when I execute it.
> base_query_with_hint = base_query.with_hint(MyTable, 
> "MAX_EXECUTION_TIME(30000)")
> base_query_with_hint.execute() # THIS DOES NOT WORK.
>
> str(base_query_with_hint)
> # Output
> # Select a, b, c from MyTable MAX_EXECUTION_TIME(30000)
>
> The hint is just rendered at the end of the query, apparently!
>
> It should render as
>
> Select /*+ MAX_EXECUTION_TIME(30000) */ a, b, c from MyTable
>
> I want it to behave exactly like 
> https://docs.sqlalchemy.org/en/13/core/selectable.html#sqlalchemy.sql.expression.Select.with_hint
>  but I'm using the Query API instead of the Select API.
>
> Another possibility: A commenter in stackoverflow suggested this is an issue 
> with the MySQL dialect not the query API.
>
>
> See comments here (they suggested I come to this mailing list): 
> https://stackoverflow.com/questions/56030825/sqlalchemy-query-api-not-working-correctly-with-hints
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sqlalchemy.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/789cd456-ce14-4624-a363-446845d94a2d%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CA%2BRjkXFL9n0g1t9FTPv7z%3DzbkvBWkjuPmqcg8S989CoczQy0fg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to