how add comment before query statement?

643 views
Skip to first unread message

lestat

unread,
Dec 12, 2011, 3:56:27 AM12/12/11
to sqlal...@googlegroups.com
For our postgresql cluster we need sometime append comment before query statement.

E.g.
q = Comment.query.all()

SELECT ... FROM comment

How append comment like this?
/*NO LOAD BALANCE*/ SELECT ... FROM comment

I try change q.statement, but can't find right solution.

Thanks!

Michael Bayer

unread,
Dec 12, 2011, 9:47:28 AM12/12/11
to sqlal...@googlegroups.com
we have select.prefix_with() which can stick it right after the SELECT, if that works....otherwise if it really has to be the first thing would need to work in some @compiles tricks.....

then as far as Query I thought we had added something for this but apparently not, you'd have to subclass that too for the moment...   :/  


--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/WR0Oa-oZAx0J.
To post to this group, send email to sqlal...@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.

bogun....@gmail.com

unread,
Dec 16, 2011, 4:32:03 PM12/16/11
to sqlal...@googlegroups.com


2011/12/12 Michael Bayer <mik...@zzzcomputing.com>

we have select.prefix_with() which can stick it right after the SELECT, if that works....otherwise if it really has to be the first thing would need to work in some @compiles tricks.....

then as far as Query I thought we had added something for this but apparently not, you'd have to subclass that too for the moment...   :/  

Hello. I have related question.
I need add "sql_cache"  keywords into select query. There is way to do this on sql layer via "prefixes" keyword argument to "select" class or via method .prefix_with of the same select class. But I have orm.Query object... And I can't find way to add prefix on it.

SA-0.6.7

Michael Bayer

unread,
Dec 16, 2011, 7:19:59 PM12/16/11
to sqlal...@googlegroups.com
On Dec 16, 2011, at 4:32 PM, bogun....@gmail.com wrote:



2011/12/12 Michael Bayer <mik...@zzzcomputing.com>
we have select.prefix_with() which can stick it right after the SELECT, if that works....otherwise if it really has to be the first thing would need to work in some @compiles tricks.....

then as far as Query I thought we had added something for this but apparently not, you'd have to subclass that too for the moment...   :/  

Hello. I have related question.
I need add "sql_cache"  keywords into select query. There is way to do this on sql layer via "prefixes" keyword argument to "select" class or via method .prefix_with of the same select class. But I have orm.Query object... And I can't find way to add prefix on it.

yeah it's a missing feature so do this:

from sqlalchemy.orm.query import Query, _generative

class MyQuery(Query):
    _prefixes = ()

    def prefix_with(self, prefixes):
        self._prefixes += prefixes

    def _compile_context(self, **kw):
        ctx = super(MyQuery, self)._compile_context(**kw)
        if self._prefixes:
           ctx.statement = ctx.statement.prefix_with(self._prefixes)
       return ctx


Session = sessionmaker(query_cls=MyQuery)




SA-0.6.7


On Dec 12, 2011, at 3:56 AM, lestat wrote:

For our postgresql cluster we need sometime append comment before query statement.

E.g.
q = Comment.query.all()

SELECT ... FROM comment

How append comment like this?
/*NO LOAD BALANCE*/ SELECT ... FROM comment

I try change q.statement, but can't find right solution.



--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
Reply all
Reply to author
Forward
0 new messages