[sqlalchemy] Re: sqlalchemy: stopping a long-running query
Heh, thanks Michael! I believe to have found a working solution, using a special cancel method that was introduced in the 2.4 psycopg2 driver. I've updated the SO post with my current solution. Thanks for the quick reply! Cody On Feb 24, 1:06 pm, Michael Bayer mike...@zzzcomputing.com wrote: I'd augment the comments on the SO post by saying you'd want to look at psycopg2 directly, and possibly ask on their mailing list, what the expected behavior and options are here. If you provide sample code to the psycopg2 folks, make sure that code is in terms of psycopg2 directly and not any SQLAlchemy, lest they dismiss your issue as something specific to SQLAlchemy. On Feb 24, 2012, at 3:47 PM, Cody Django wrote: Hi guys -- hopefully this is an easy answer for someone! I've also posted the problem to stack overflow: http://stackoverflow.com/questions/9437498/sqlalchemy-stopping-a-long... I'm using sqlalchemy to query postgres. If a client timeout occurs, I'd like to stop/cancel the long running postgres queries from another thread. The thread has access to the Session or Connection object. At this point I've tried: session.bind.raw_connection().close() and session.connection().close() and session.close and session.transaction.close() But no matter what I try, the postgres query still continues until it's end. I know this from watching pg in top. Shouldn't this be fairly easy to do? I'm I missing something? Is this impossible without getting the pid and sending a stop signal directly? Thanks so much, Cody -- 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 athttp://groups.google.com/group/sqlalchemy?hl=en. -- 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] dynamically set table_name at runtime
Hello! I would like to dynamically set/change the table that is mapped in my python object, as instantiated through the declarative style. class Feature(Base, GeometryTableMixIn): this is dynamically created to use a table and pk_column determined at runtime __table_args__ = { schema: 'a_schema', autoload: True, autoload_with: Session.bind, useexisting: True } wkb_geometry = GeometryColumn('wkb_geometry', Geometry(srid=4269)) def __init__(self, *args, **kwargs): self.__tablename__ = kwargs['tablename'] self.pk_id = Column('%s' % kwargs['pk_id'], types.Integer, primary_key=True, autoincrement=False) super(Feature, self).__init__(*args, **kwargs) This doesn't work: InvalidRequestError: Class class 'javelin.model.feature.Feature' does not have a __table__ or __tablename__ specified and does not inherit from an existing table-mapped class. Could this possibly be done through another approach? Suggestions are greatly appreciated. -- 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: dynamically set table_name at runtime
Wow somebody already brought this to light! http://stackoverflow.com/questions/2768607/dynamic-class-creation-in-sqlalchemy On Jun 20, 11:36 am, Cody Django codydja...@gmail.com wrote: Hello! I would like to dynamically set/change the table that is mapped in my python object, as instantiated through the declarative style. class Feature(Base, GeometryTableMixIn): this is dynamically created to use a table and pk_column determined at runtime __table_args__ = { schema: 'a_schema', autoload: True, autoload_with: Session.bind, useexisting: True } wkb_geometry = GeometryColumn('wkb_geometry', Geometry(srid=4269)) def __init__(self, *args, **kwargs): self.__tablename__ = kwargs['tablename'] self.pk_id = Column('%s' % kwargs['pk_id'], types.Integer, primary_key=True, autoincrement=False) super(Feature, self).__init__(*args, **kwargs) This doesn't work: InvalidRequestError: Class class 'javelin.model.feature.Feature' does not have a __table__ or __tablename__ specified and does not inherit from an existing table-mapped class. Could this possibly be done through another approach? Suggestions are greatly appreciated. -- 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: Declaring compound primary key on reflective model
Thanks! On Jun 10, 1:06 pm, A.M. age...@themactionfaction.com wrote: On Jun 10, 2011, at 2:25 PM, Cody Django wrote: Hi all -- I'm new on pylons, coming from a django background. I'm working on a mapfish project. I'd like to autoload a model based on a db table, but in doing so I get the error could not assemble any primary key columns for mapped table. The table itself is a postgres view with no declared primary key column, so it makes sense that no primary key columns are detected. I figure it is possible to define which columns to use as the primary key in the __table_args__ dict, but I have yet to figure out exactly how. Tips, please! I do the same thing: newtable = Table(name, meta, *props, autoload=True ) where props = ColumnCollection(Column('id',Integer,primary_key=True)) SQLAlchemy overwrites the autoloaded info with the passed-in column info. Cheers, M -- 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] Declaring compound primary key on reflective model
Hi all -- I'm new on pylons, coming from a django background. I'm working on a mapfish project. I'd like to autoload a model based on a db table, but in doing so I get the error could not assemble any primary key columns for mapped table. The table itself is a postgres view with no declared primary key column, so it makes sense that no primary key columns are detected. I figure it is possible to define which columns to use as the primary key in the __table_args__ dict, but I have yet to figure out exactly how. Tips, please! Cody -- 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: Declaring compound primary key on reflective model
A related query: reflecting two tables, and wanting to identity a one- to-one relation based on a mutual id field on the model class. Cody On Jun 10, 11:25 am, Cody Django codydja...@gmail.com wrote: Hi all -- I'm new on pylons, coming from a django background. I'm working on a mapfish project. I'd like to autoload a model based on a db table, but in doing so I get the error could not assemble any primary key columns for mapped table. The table itself is a postgres view with no declared primary key column, so it makes sense that no primary key columns are detected. I figure it is possible to define which columns to use as the primary key in the __table_args__ dict, but I have yet to figure out exactly how. Tips, please! Cody -- 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.