trinodb / trino-python-client

Python client for Trino
Apache License 2.0
311 stars 154 forks source link

Support for primary and foreign keys in sqlalchemy #205

Open mdesmet opened 2 years ago

mdesmet commented 2 years ago

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)
ebyhr commented 2 years ago

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