Skip to main content
22 events
when toggle format what by license comment
Jan 17, 2019 at 20:52 history edited user1822 CC BY-SA 4.0
added 31 characters in body
Jan 17, 2019 at 20:49 vote accept thousandsofthem
Jan 17, 2019 at 20:48 history edited Evan Carroll CC BY-SA 4.0
added 32 characters in body; edited title
Jan 17, 2019 at 20:46 comment added Evan Carroll Can you mark the answer as chosen if you accept it (I'm guessing so since ou awarded the bounty)
S Jan 17, 2019 at 20:33 history bounty ended thousandsofthem
S Jan 17, 2019 at 20:33 history notice removed thousandsofthem
Jan 17, 2019 at 16:32 answer added Evan Carroll timeline score: 0
Jan 17, 2019 at 16:25 answer added Joe W timeline score: 0
Jan 17, 2019 at 16:08 history edited Evan Carroll CC BY-SA 4.0
added 73 characters in body
Jan 17, 2019 at 10:21 comment added MarcoP What do you mean with: Will INSERT INTO ... SELECT(...) be enough? this wont work: (assuming account_id = 1 and change = 20) insert into transactions (account_id,change,balance) select 1,20,(balance+20) from transactions WHERE account_id = 1 ORDER BY id DESC LIMIT 1 for update;
Jan 17, 2019 at 10:14 comment added Arkhena If you want to do it that way (and that way is wrong as explained by a_horse_with_no_name) you should consider using the serializable isolation level. You'll find more informations about it in Postgres documentation (postgresql.org/docs/11/transaction-iso.html).
Jan 16, 2019 at 15:41 comment added HelloWorld You're either going to have to use table locks, or you could make another table with balance and use a trigger.
S Jan 13, 2019 at 10:30 history bounty started thousandsofthem
S Jan 13, 2019 at 10:30 history notice added thousandsofthem Draw attention
Jan 11, 2019 at 15:29 comment added thousandsofthem @a_horse_with_no_name it's way slower, also keeping calculated balance prevents just updating historic records
Jan 11, 2019 at 15:09 comment added user1822 You shouldn't be storing the balance, but calculate it from the existing transactions.
Jan 11, 2019 at 15:05 answer added jjanes timeline score: 0
Jan 11, 2019 at 12:33 comment added thousandsofthem > Just do it in the same connection/transaction. There are no guarantee still without database support. Stuff happens.
Jan 11, 2019 at 11:50 comment added ypercubeᵀᴹ @Philᵀᴹ that would still allow 2 transactions to both add 100 to the latest balance (say it was 50) and have 2 rows inserted with balance 150.
Jan 11, 2019 at 10:44 comment added Philᵀᴹ Just do it in the same connection/transaction. Do you have control over that in your code?
Jan 11, 2019 at 10:30 review First posts
Jan 11, 2019 at 12:27
Jan 11, 2019 at 10:26 history asked thousandsofthem CC BY-SA 4.0