SQLAlchemy Primary Index

Connectivity
Connectivity covers the mechanisms for connecting to the Teradata Database, including driver connectivity via JDBC or ODBC.
Enthusiast

SQLAlchemy Primary Index

Hello!

 

I'm using teradatasql module to interact with a teradata db via sqlalchemy. Could you provide a way how to decribe table with a PRIMARY INDEX within a table like here:

 

user = Table('user', metadata,
    Column('user_id', Integer, primary_key=True),
    Column('user_name', String(16), nullable=False),
    Column('email_address', String(60)),
    Column('nickname', String(50), nullable=False)
)

 or within an ORM:

 

class User(Base):
...     __tablename__ = 'users'
...
...     id = Column(Integer, primary_key=True)
...     name = Column(String)
...     fullname = Column(String)
...     nickname = Column(String)
Tags (1)
4 REPLIES 4
Teradata Employee

Re: SQLAlchemy Primary Index

You can use a cursor to execute a "show table" query. For example cursor.execute("show table user"). If you would like to use sqlalchemy, there is a package called teradatasqlalchemy that implements the dialect for Teradata.

Enthusiast

Re: SQLAlchemy Primary Index

Thank you for your answer! 

 

I'm already using sqlalchemy with the teradatasqlalchemy module. But I didn't find a way how to create a table with "primary index". Could you privide a minimal example.

 

Thank you in advance!

Teradata Employee

Re: SQLAlchemy Primary Index

You should be able to:

from teradatasqlalchemy.compiler import TDCreateTablePost

then use the teradata_post_create parameter in Table

 

Yes, I suggest looking at some of the tests:

https://github.com/Teradata/sqlalchemy-teradata/blob/dev/test/unit/test_td_ddl.py#L262

 

Enthusiast

Re: SQLAlchemy Primary Index

Thank you!