[sqlalchemy] Re: miss for postgres_from in update() :(

2009-03-05 Thread Michael Bayer


visit_update() would have to be rewritten in the base compiler to  
support addition of extra components.


On Mar 5, 2009, at 5:05 AM, sector119 wrote:

>
> I create a small (4 lines) patch for databases/postgres.py
>
> def _append_from(self, text, stmt):
>return text.replace(' WHERE', ' FROM ' + string.join([table.name
> for table in stmt.kwargs['postgres_from']], ', ') + ' WHERE')
>
> def visit_update(self, update_stmt):
>  text = super(PGCompiler, self).visit_update(update_stmt)
>  if 'postgres_returning' in update_stmt.kwargs:
>text = self._append_returning(text, update_stmt)
>  if 'postgres_from' in update_stmt.kwargs:
>text = self._append_from(text, update_stmt)
>  return text
>
> But I think that text.replace(...) is ugly, may be you know how to
> insert FROM clause before WHERE without replacements?
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: miss for postgres_from in update() :(

2009-03-05 Thread sector119

I create a small (4 lines) patch for databases/postgres.py

def _append_from(self, text, stmt):
return text.replace(' WHERE', ' FROM ' + string.join([table.name
for table in stmt.kwargs['postgres_from']], ', ') + ' WHERE')

def visit_update(self, update_stmt):
  text = super(PGCompiler, self).visit_update(update_stmt)
  if 'postgres_returning' in update_stmt.kwargs:
text = self._append_returning(text, update_stmt)
  if 'postgres_from' in update_stmt.kwargs:
text = self._append_from(text, update_stmt)
  return text

But I think that text.replace(...) is ugly, may be you know how to
insert FROM clause before WHERE without replacements?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---