On Thu, Jul 20, 2017 at 5:35 AM, Fredrik Blomqvist <fredrik.blomqvist...@gmail.com> wrote: > There seems to be surprisingly little information about how to load a table > manually if you set the autoload flag to False. > There is a fairly new question on StackOverflow that has not been answered > properly either: https://stackoverflow.com/q/43042044/998919. > Is there a function (e.g. ".load()") that can be called to load a table that > has not been loaded yet?
hi there - this can be satisfied using the extend_existing flag: t = Table("sometable", metadata) Table("somedata", autoload_with=engine, extend_existing=True) http://docs.sqlalchemy.org/en/latest/core/metadata.html#sqlalchemy.schema.Table.params.extend_existing > > A use-case for this is the following: > > You have two sets of tables: A and B. > > A: Depends on no-one > B: Cannot be created with SQLAlchemy (e.g. PostgreSQL views) and depend on > A. > > If you then want to reflect B, we can call those a set of objects C. > > C is clearly dependent on B. However, when A is created (using e.g. > create_all()) SQLAlchemy first loads C. If autoload is true on C, the > program will error out. > > If you could instead choose to load C later, this scenario could still work > out. > > Any thoughts? I'm not following: "You have two sets of tables: A and B." OK "B: Cannot be created with SQLAlchemy (e.g. PostgreSQL views) and depend on A." OK...then B is *not* a table, it is a view. I think here we need to distinguish between SQLAlchemy in Python Table() (which would load for B) and "CREATE TABLE" vs. "CREATE VIEW" in the database. "A: "depends on no-one"", ok so lets say A is a "CREATE TABLE A" in the database "When A is created (e.g. using create_all()" - OK, then there has been no "CREATE TABLE", you just have Table, OK, there is no "A" in the database (so why are we using reflection?) "SQLAlchemy first loads C" - OK I think there is some confusion here. "create_all()" emits CREATE TABLE, it does not "load" tables (other than checking if each immediate table exists). you call "create_all()" when you only have Python Table objects that weren't created in the database "If you then want to reflect B, we can call those a set of objects C." - I don't understand this sentence. if B is "CREATE VIEW B AS SELECT ....", what is C? another view that depends on B ? It would be much clearer if you could illustrate with code what you are trying to do. thanks! > > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > 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 https://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- 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 https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.