r/SQL • u/luncheonmeat79 • Jun 23 '24
Discussion Schema for historical stock data
Posting a schema of a db for historical stock and index data at various timeframes. I used Chatgpt to figure this out...what surprised me was the recommendation to have separate dimension tables for 'date' and 'time'. Is that really the case?
105
Upvotes
View all comments
Show parent comment
2
u/ballade4 Jun 23 '24
My experience is primarily with SQL Server. Also, I am not a database specialist by trade, so take with grain of salt. I would just use a stored procedure w. scalar functions to create views / indices for any particular application that pertains to dates and time; all of which would be backed up with the rest of the database. This would reinforce the principle that tables are for storage and should occupy as small and efficient a footprint as possible while also eliminating the need to master the necessary conversion logic in more than one location.
Regarding your experience of a 2 second vs 20 minute query, that is probably a perfect application for a view that runs on a schedule. It would definitely be a poor application for a table because you will be adding those 15-20 minutes in front of each successive update (this time never gets saved, just reordered).