Re: [sqlalchemy] Automatically add Index on same columns in ForeignKeyConstraint in Postgresql using Custom DDL/Compilation

2021-06-25 Thread mkmo...@gmail.com
Hi Mike, Thanks for your feedback. I'll leave your suggestion here if anyone comes across this: from sqlalchemy import event, Table @event.listens_for(Table, 'before_create') def add_index_on_foreign_key_columns(table, connection, **kwargs): for foreign_key in

Re: [sqlalchemy] Automatically add Index on same columns in ForeignKeyConstraint in Postgresql using Custom DDL/Compilation

2021-06-25 Thread Mike Bayer
On Fri, Jun 25, 2021, at 11:58 AM, mkmo...@gmail.com wrote: > > When using PostgreSQL, creating a foreign key on a column in a table does not > automatically index that column, unlike Oracle or MySQL. > > I would like to get SQLAlchemy to automatically create an index on the same > columns

[sqlalchemy] Automatically add Index on same columns in ForeignKeyConstraint in Postgresql using Custom DDL/Compilation

2021-06-25 Thread mkmo...@gmail.com
When using PostgreSQL, creating a foreign key on a column in a table does not automatically index that column, unlike Oracle or MySQL. I would like to get SQLAlchemy to automatically create an index on the same columns that are specified in a ForeingKeyConstraint. For example, if I have a