Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select table from other schema

Tags:

sqlalchemy

I have a table from schema "test":

class AttributeConversion(Base):
    __tablename__ = 'test.attribute_conversion'

How to select records from this table?

SQLAlchemy generates SQL:

select * from "test.attribute_conversion"

But it doesn't work. The correct query must be:

select * from test.attribute_conversion  (without quotes)
like image 706
Bdfy Avatar asked May 16 '11 13:05

Bdfy


People also ask

How do I SELECT a table from a schema?

The easiest way to find all tables in SQL is to query the INFORMATION_SCHEMA views. You do this by specifying the information schema, then the “tables” view. Here's an example. SELECT table_name, table_schema, table_type FROM information_schema.

How do I copy a table from another schema?

1) Use the ALTER TABLE ... RENAME command and parameter to move the table to the target schema. 2) Use the CREATE TABLE ... CLONE command and parameter to clone the table in the target schema.

How do I SELECT a schema in SQL?

You can get a list of the schemas using an SSMS or T-SQL query. To do this in SSMS, you would connect to the SQL instance, expand the SQL database and view the schemas under the security folder. Alternatively, you could use the sys. schemas to get a list of database schemas and their respective owners.


1 Answers

You can explicity specify a schema name for a table:

class AttributeConversion(Base)
    __tablename__ = 'attribute_conversion'
    __table_args__ = {'schema' : 'test'}

See documentation on specifying the schema name.

like image 170
van Avatar answered Sep 24 '22 15:09

van