Hello, -which one these is better way to store da...
# sql
l
Hello, -which one these is better way to store data? -can data in json later be used in count and summation?
s
If you might need to add more metadata, create individual columns. It's significantly easier for Postgres to find records with individual columns than it is to find fields inside JSON. It also makes it much easier to update a whole bunch of rows at once, as you'll only have to update 1 column for each record, instead of having to rewrite the JSON for each row.
l
oh okay great. for now I have 13 keys. so that's why I'm having them as metadata(rows) and not columns.
wanted to know if JSON is any better
s
You can certainly use JSON, and in some cases it might be preferable. For example, I store different server configs in JSON because it's easier, but I only have 3 rows (1 for each environment - local, staging, production) and only ever need to retrieve 1 row. Each row has the environment name as a separate column so it's easy to look up. I don't need to find out if a specific config contains a specific setting - I'm retrieving the entire contents of the row and then loading the config into a local state store as-is. For any table where you need to find data based on a specific field, individual columns are better. For example, if you wanted to find all houses which have a pool but also have more than 3 bedrooms, it would take Postgres much longer to find results matching that data if it's stored as JSON than it would if each property had it's own column. Storing everything as JSON is where NoSQL like Mongo or Firebase are better, and Postgres/Supabase isn't really built around being really effective at that.
l
Thank you so much for the feedback ❤️