trino-python-client icon indicating copy to clipboard operation
trino-python-client copied to clipboard

Support for primary and foreign keys in sqlalchemy

Open mdesmet opened this issue 3 years ago • 2 comments

In sqlalchemy a user can define primary keys and foreign keys as in the following example.

from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey
metadata_obj = MetaData()
users = Table('users', metadata_obj,
    Column('id', Integer, primary_key=True),
    Column('name', String),
    Column('fullname', String),
)

addresses = Table('addresses', metadata_obj,
  Column('id', Integer, primary_key=True),
  Column('user_id', None, ForeignKey('users.id')),
  Column('email_address', String, nullable=False)
 )

Primary key or foreign key constraints are not (yet) supported in Trino (For example Snowflake allows to define constraints but is not actually enforcing)

sqlalchemy might depend on these configurations to generate CRUD queries (Trino also doesn't support things like auto increments so there might be other issues as well).

We can either:

  1. Block setting up constraints
  2. Allow setting up constraints (but silently ignoring them from the database perspective)

mdesmet avatar Jul 20 '22 10:07 mdesmet

Phoenix connector already supports primary_key column property. Generally, we prefer failure to ignoring in this project (including Trino).

ebyhr avatar Jul 20 '22 10:07 ebyhr