Hi Michael, Do I need to redefined mapped class ssh_host_keys as a Table object?
ssh_host_keys = Table('ssh_host_keys', metadata, Column('hostname', VARCHAR(30), primary_key=True), Column('pub', VARCHAR(1600)), Column('sha256', CHAR(64)), Column('priv', VARCHAR(2000)), schema='keys', mysql_engine='InnoDB' ) Do I need to convert mapped class 'Host' to a Table object as well? I would prefer not to touch this class, since it is part of a separate module, but if needed, it is possible. class Host(Base): __tablename__ = 'hosts' __table_args__ = {'mysql_engine': 'InnoDB'} id = Column(u'HostID', INTEGER(), primary_key=True) hostname = Column(String(length=30)) Can you please give an example how to use schema with a query.join(), for my scenario (two sessions, one for each DB connection)? Thanks, Brian On 20 January 2015 at 16:12, Michael Bayer <mike...@zzzcomputing.com> wrote: > > > Jonathan Vanasco <jonat...@findmeon.com> wrote: > > > > > > > On Tuesday, January 20, 2015 at 5:34:27 PM UTC-5, Brian Glogower wrote: > > > > Thanks for the idea. Do you have an example? > > > > I don't have a personal example handle, but from the docs... > > > > > http://docs.sqlalchemy.org/en/rel_0_9/orm/tutorial.html#using-literal-sql > > > > >>> session.query(User).from_statement( > > ... text("SELECT * FROM users where name=:name")). > > \ > > > > ... params(name='ed').all() > > [<User(name='ed', fullname='Ed Jones', password='f8s7ccs')>] > > > > > > So you should be able to do something like: > > > > query = Session.query(Host)\ > > .from_statement( > > sqlaclhemy.text("SELECT hostname, sha256 FROM DATABASE1.hosts > LEFT JOIN DATABASE2.ssh_host_keys ssh_host_keys ON ssh_host_keys.hostname > == hosts.hostname) > > ) > > why is text() needed here? these could be the Table objects set up with > “schema=‘schema name’” to start with, then you’d just do the join with > query.join(). > > > -- > 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 sqlalchemy+unsubscr...@googlegroups.com. > To post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at http://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. > -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.