support statement level hints

Issue #3206 resolved
Mike Bayer repo owner created an issue
stmt = select([...]).with_statement_hint("some statement hint", "mysql")

this will send None into with_hint(), which will collect statement-level hints separately and render them by default at the end of the SELECT.

Comments (3)

  1. Mike Bayer reporter
    • Added new method :meth:.Select.with_statement_hint and ORM method :meth:.Query.with_statement_hint to support statement-level hints that are not specific to a table. fixes #3206

    → <<cset f82f6d55dc05>>

  2. Prabhath Nanisetty

    This doesn't seem to work (both with_hint() and with_statement_hint())... In compile.py (https://github.com/zzzeek/sqlalchemy/blob/master/lib/sqlalchemy/sql/compiler.py#L1667) you call _setup_select_hints... which returns a tuple containing hint_text.

    The issue is that this function creates the byfrom dictionary and for hint_text it calls get_select_hint_text (located here: https://github.com/zzzeek/sqlalchemy/blob/master/lib/sqlalchemy/sql/compiler.py#L1468) which returns None... So , no hints ever get added (at least when I'm running it) to my statements.

  3. Mike Bayer reporter

    Hi there -

    with_statement_hint() does not make use of the _setup_select_hints method in the default dialect, it uses the get_statement_hint_text() method.

    If you are observing a bug, please post an issue with complete test cases which, when run, illustrate a failing assertion (e.g. an mcve. These features are unit tested (see https://bitbucket.org/zzzeek/sqlalchemy/src/ce62fa2eed1d93c9b6e383e48dcfaf5380b86915/test/sql/test_compiler.py?at=master&fileviewer=file-view-default#test_compiler.py-2631 ) so "doesn't seem to work" is unfortunately not specific enough for us to respond. thanks!

  4. Log in to comment