Skip to content

sqlalchemy inspect constraints support #15788

Closed as not planned
Closed as not planned

Description

@arkeodev

Upon scrutinizing the schema reflection for Big Query, I am able to discern the dataset lists and glean information about the columns to a certain extent. Although it's not a mandatory requirement, I have the capability to establish primary and foreign keys on tables. However, when I attempt to retrieve this information using an inspector, the following code doesn't yield the expected results:

from sqlalchemy import inspect, create_engine
engine = create_engine('...')
inspector = inspect(engine)
primary_key = inspector.get_pk_constraint("table_name")  # returns empty
foreign_keys = inspector.get_foreign_keys("table_name")  # returns empty

Given this situation, I am wondering if there's an alternative method to extract this data without having to resort to SQL Queries on INFORMATION_SCHEMA?

Activity

  1. added
    api: bigquery
    on May 25, 2023
  2. richard-sparq commented on Jul 14, 2023

    @richard-sparq

    Clearly these methods get_pk_constraint() and get_foreign_keys() aren't implemented in bigquery-sqlalchemy (even though it is possible now to define foreign & primary key constraints in BQ). Just wondering @arkeodev if you have any further insights/workarounds to obtain these constraints?

  3. bush-david commented on Aug 1, 2023

    @bush-david

    Will there eventually be support for unenforced BQ primary and foreign key constrains in bigquery-sqlalchemy?

  4. self-assigned this
    on Feb 22, 2024
  5. chalmerlowe commented on Mar 2, 2026

    @chalmerlowe
    Contributor

    This issue was moved from the following repo as part of the monorepo migration: googleapis/python-bigquery-sqlalchemy

  6. daniel-sanche commented on May 28, 2026

    @daniel-sanche
    Contributor

    This issue is being bulk closed due to inactivity. Please re-open if you think this still requires attention, and we'll take another look. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: bigquery

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions