How do I specify a catalog if I'm defining mutiple tables using the sqlalchemy ORM style?

Open
#446 6 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
python, sqlalchemy
Domain
databases

Research direction

Start with the Foo and Bar declarative examples in the issue and trace how their schema and table names reach the connector's catalog setting. Confirm whether declarative mappings can carry distinct catalogs and define the expected behavior for querying both fully qualified tables.

Written by the indexing model from the issue text.

Description

I have two tables I want to query from, the fully qualified names are foo_catalog.foo_schema.foo and bar_catalog.bar_schema.bar. I can specify a schema and a tablename in the table definition but I only get a chance to specify the catalog once in the connection.

How do I specify a catalog using declarative base style?

If I was writing raw sql I could query accross both catalogs no problem.

class Base(declarative_base(metaclass=DeclarativeABCMeta)):
    __abstract__ = True

class Foo(Base):
    __tablename__ = "foo"
    __table_args__ = { "schema": "foo_schema"}

    id: Mapped[int] = mapped_column(name="id", type_=INTEGER,  primary_key=True)
class Bar(Base):
    __tablename__ = "bar"
    __table_args__ = { "schema": "bar_schema"}

    id: Mapped[int] = mapped_column(name="id", type_=INTEGER,  primary_key=True)
Dominant language
Python
Stars
236
Forks
162
Avg merge
13h 13m
Merged PRs (30d)
23

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from databricks/databricks-sql-python

All issues in databricks/databricks-sql-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.