https://supabase.com/ logo
Join Discord
Powered by
# sql
  • j

    jensen

    06/06/2022, 7:40 AM
    I didn't answer your question about the date column as your primary key because I haven't tried it. How are you handling time zones?
  • m

    Muezz

    06/06/2022, 7:41 AM
    As my app is going to be used only for myself in my own personal business, I am not worried about timelines. So I am only using "date"...as in year, month and date.
  • m

    Muezz

    06/06/2022, 7:41 AM
    timezones*
  • j

    jensen

    06/06/2022, 7:41 AM
    I don't think I would use a trigger with a second table if I could avoid it
  • j

    jensen

    06/06/2022, 7:41 AM
    Maybe I would use a view
  • j

    jensen

    06/06/2022, 7:42 AM
    That aggregates the transactions for each date.
  • j

    jensen

    06/06/2022, 7:43 AM
    if that proved to be too slow, then maybe I would consider caching it in another table like you've suggested. I try to let the db do the hard work if I can
  • m

    Muezz

    06/06/2022, 7:43 AM
    Can you elaborate? I dont understand. Why would you avoid it? Is there a particular reason? I know I can use the aggregation methods (and they work fine). But my number of trnsactions would increase so much every single day that I am sure calculating balances on the go would be a waste of resources. Thats why I want to cache it.
  • j

    jensen

    06/06/2022, 7:44 AM
    since you have suggested that you are the only one using it, then easiest is to use a view
  • m

    Muezz

    06/06/2022, 7:44 AM
    Thats the reason I am looking into this.
  • j

    jensen

    06/06/2022, 7:44 AM
    But have you proven it to be too slow?
  • j

    jensen

    06/06/2022, 7:45 AM
    Views are pretty powerful, if you haven't tried that yet, then I would experiment
  • m

    Muezz

    06/06/2022, 7:45 AM
    Not really. i am assuming this would happen when my rows get into millions.
  • j

    jensen

    06/06/2022, 7:45 AM
    Postgres is pretty impressive
  • m

    Muezz

    06/06/2022, 7:45 AM
    I'll give it a try.
  • j

    jensen

    06/06/2022, 7:45 AM
    Let me know how it goes. It's easy to add a million transactions into a test db to know for sure
  • j

    jensen

    06/06/2022, 7:46 AM
    then you can optimize against that test data until you have a solution that you know will work
  • m

    Muezz

    06/06/2022, 7:46 AM
    I will try both methods and see which works better
  • j

    jensen

    06/06/2022, 7:47 AM
    duplicating data should be avoided, it means you need to keep it in sync yourself (instead of letting the rdbms doing it with a view)
  • j

    jensen

    06/06/2022, 7:47 AM
    If I can calculate new data with the existing data, and I store that calculated data, I consider it duplicate state.
  • j

    jensen

    06/06/2022, 7:48 AM
    So I avoid that until I am forced into it after measuring and trying to optimize
  • m

    Muezz

    06/06/2022, 7:48 AM
    Oh. I understand now what you meant.
  • j

    jensen

    06/06/2022, 7:50 AM
    Sometimes caching is a necessary evil, but it is rarely my first approach since it can easily lead to desyncs
  • m

    Muezz

    06/06/2022, 8:38 AM
    It takes about 3 seconds to sum a single column from 10 million rows which is acceptable I think.
  • m

    Muezz

    06/06/2022, 8:39 AM
    I used view for this
  • m

    Muezz

    06/06/2022, 8:39 AM
    Caching would obviously be much faster than this but I think that this is acceptable
  • m

    Muezz

    06/06/2022, 8:51 AM
    Also, views cannot take in arguments for the WHERE statements as far as I can tell. So I might end up using a postgres database function instead to do the same query as my VIEW.
  • j

    jensen

    06/06/2022, 2:48 PM
    It may be possible to make that query faster. Do you have much experience with explain analyze? Also when you query a view table you should be able to use a where clause.
  • m

    Muezz

    06/06/2022, 3:23 PM
    No I dont. I am hearing about t for the first time. What is it? Do you mean where clauses inside View or when selecting from view? If its the later, whats the point of that. I am already getting a single value from it.
  • j

    jensen

    06/06/2022, 3:32 PM
    Seems I’ve hit the limit of knowing what your specific use case is. Check the docs out, they are great. Maybe you can use materialized views that are updated when necessary.
1...444546...52Latest