Do stored procedures run in database transaction in Postgres?

Strictly speaking, Postgres did not have stored procedures as defined in the ISO/IEC standard before version 11. The term is often used incorrectly to refer to functions, which provide much of the same functionality (and more) as other RDBMS provide with “stored procedures”. The main difference being transaction handling. What are the differences between “Stored … Read more

What are the known ways to store a tree structure in a relational DB? [closed]

As always: there is no best solution. Each solution makes different things easier or harder. The right solution for you depends on which operation you will do most. Naive Approach with parent-id: Pros: Easy to implement Easy to move a big subtree to another parent Insert is cheap Needed Fields directly accessible in SQL Cons: … Read more

Storing time-series data, relational or non?

Definitely Relational. Unlimited flexibility and expansion. Two corrections, both in concept and application, followed by an elevation. Correction It is not “filtering out the un-needed data”; it is selecting only the needed data. Yes, of course, if you have an Index to support the columns identified in the WHERE clause, it is very fast, and … Read more

Why use multiple columns as primary keys (composite primary key)

Your understanding is correct. You would do this in many cases. One example is in a relationship like OrderHeader and OrderDetail. The PK in OrderHeader might be OrderNumber. The PK in OrderDetail might be OrderNumber AND LineNumber. If it was either of those two, it would not be unique, but the combination of the two … Read more

Modeling Product Variants

You could have a design like: +—————+ +——————-+ | PRODUCTS |—–< PRODUCT_VARIANTS | +—————+ +——————-+ | #product_id | | #product_id | | product_name | | #variant_id | +—————+ | sku_id | | +——————-+ | | +——–^——–+ +——–^——–+ | PRODUCT_OPTIONS |—–< VARIANT_VALUES | +—————–+ +—————–+ | #product_id | | #product_id | | #option_id | | #variant_id … Read more