[Flask] SQLAlchemy - One Class - Several Tables

John Robson John.Robson at usp.br
Thu Jul 21 20:14:35 EDT 2016


Hi everyone,

I want to store the minute price of all 500 stocks from S&P 500.  This 
means more than 500 million of rows + almost 200K updates per day + 
(sometimes) past values must be updated (to adjust ex-dividend, splits).

Instead of creating a BIG table, I would like to create 500 tables (one 
for each stock). They have the same structure/columns (open, high, low, 
close, volume).

There is some way of creating only one Class to map all those 500 
tables, or I need to create 500 classes?

* I found this code of a Dynamically table: 
https://gist.github.com/munro/3686e3b060c2cd7959350ea8bf77ff2c

Is this the best approach for CRUDing this 500 tables and still using 
all the SQLAlchemy features?

* I also found about "Single Table Inheritance": 
http://docs.sqlalchemy.org/en/latest/orm/inheritance.html#single-table-inheritance

So, I wonder what is the best approach to create and manage this DB with 
500 tables.

Thank you,
John



More information about the Flask mailing list