Skip to content

How to add dialect specific index (postgres)? #571

Closed Answered by fishfacegit
fishfacegit asked this question in Questions
Discussion options

You must be logged in to vote

Defining the index via SQLAlchemy separate from class will do the trick.

from sqlmodel import Field, SQLModel, Column
from sqlalchemy import Text, Index
import datetime


class Hero(SQLModel, table=True):
    date_of_birth: datetime.date = Field(nullable=False, primary_key=True)
    universe_time: datetime.datetime
    likes_banana: bool = Field(nullable=True)
    name: str = Field(sa_column=Column(Text()))

Index('ix_hero_likes_banana', Hero.likes_banana, postgresql_using='hash')

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by fishfacegit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
1 participant