« first day (3250 days earlier)      last day (1618 days later) » 

12:14 AM
No it doesn’t
4
 
 
7 hours later…
7:14 AM
Morning
 
Morning
 
8:00 AM
Morning
 
Morning
 
morning
 
8:47 AM
*orning
 
9:15 AM
Morning
 
A J
9:27 AM
Afternoon
 
A J
@PeterVandivier That's a weird way to yawn. :P
 
Jun 12 at 10:39, by ypercubeᵀᴹ
it's always morning in the Heap™ – Consultancy
Commandment 1
 
A J
Jun 12 at 10:05, by Philᵀᴹ
select CASE WHEN DATEPART(HH, GETDATE()) >= 0 AND DATEPART(HH, GETDATE())<12 THEN 'Morning' ELSE 'AFTERNOON' END as Heap_Greeting ;
 
apocryphal
heresy
blasphemy
 
A J
9:41 AM
I came here to ask a question.
Suppose I am managing the amount in the user wallet. There'd be a statement of withdrawl and deposit. Now, I want to keep entries for previous amount and updated amount. To get previous amount, I might need to use a subquery. So, would it be an optimized way? Or is there a better way to do this?
There's gonna be a lot of entries in the statement table.
 
closed as tip of the icebrg
slash too broad
"what's the best way?"
"the way that works"
 
A J
That's what my senior told me.
 
smart guy
 
"better" is also a matter of opinion, so there's another close reason
 
lag() and lead()
 
A J
9:46 AM
Forget the second question then.
 
Anyway, if you keep all transactions, you could, say, create a view with a running total and get all the previous amounts from it
 
A J
Hmm.
Would it be any different from keeping a table for remaining balance and updating it as per deposit and withdrawl?
 
Keeping the current balance in a dedicated table may be a good idea anyway. And if it's specifically the directly previous balance that you most often want, then perhaps it wouldn't make much difference to maintain two balance values instead of one.
 
A J
In the end, I'd still need to use a subquery to get previous balance. Right?
 
57
Q: Writing a simple bank schema: How should I keep my balances in sync with their transaction history?

Nick ChammasI am writing the schema for a simple bank database. Here are the basic specifications: The database will store transactions against a user and currency. Every user has one balance per currency, so each balance is simply the sum of all transactions against a given user and currency. A balance ...

 
9:59 AM
@AJ If you are considering to maintain two balance columns, PreviousBalance and CurrentBalance, then no, you update both with a single update, when a new transaction occurs, and then you have the previous balance available to you directly. Unless I'm missing something.
 
A J
It's actually similar to what Paul has linked.
@AndriyM I still need to fetch previous balance somehow when inserting a new transaction record.
 
I didn't know you needed to store the current balance along with the transaction amount in a single record. I thought the balance value was in one table and the transactions in another (possibly more than one other, seeing as you have deposits and withdrawals). I imagined the balance would be updated by a trigger or triggers on the transaction table(s).
 
A J
@AndriyM Nah. It's actually what you thought.
I need to use the current balance from another table as previous balance, store it in the transactions table, add or subtract the amount depending on the type of transaction, and save the final value in the transactions and current balance table.
 
@AJ if your question can be distilled down to "i just updated x to x.new, how do i see what x.old was?", then answers are gonna be platform specific
 
A J
How?
 
10:11 AM
but that's a different question from "how do i see what the running balance was at any point in time"
 
I think we're basically at a point where we need to know more about the schema
Consequently, the question looks more and more like it needs to be asked on the main
 
if postgres: https://til.hashrocket.com/posts/8b5caaa8c3-postgresql-returning
if sql server: https://www.mssqltips.com/sqlservertip/2342/understanding-sql-server-inserted-and-deleted-tables-for-dml-triggers/
...off the top of my head
among other options for either
but at some point, "jfdi" is valid advice. you need to have a schema about which you can form specific complaints
 
A J
@AndriyM I am building schema right now.
@PeterVandivier what about mysql?
 
🤷‍♂️i don't know mysql that well, but i'm sure it has an analogue to those two
looks like it may not have one actually
well, two calls is two calls 🤷‍♂️ nbd
 
A J
ohh
Refresh it if you have opened the page already.
 
10:20 AM
fwiw - dbfiddle.uk/?rdbms=mysql_8.0 has mysql 5.7 & 8
 
Still showing "Waiting for sqlfiddle.com..."
Didn't know it became so slow lately
Or maybe it's only today, and maybe only for me
 
A J
I just have to copy the url from the address bar or there is a different url?
brb
 
sql fiddle has never been stable for me, part of why i evangelize for dbfiddle
 
@PeterVandivier It would probably make sense to be specific, because dbfiddle.uk isn't the only dbfiddle there is. There's also db-fiddle.com
Maybe there are others too, or will be later
 
#brandingProblems
 
10:25 AM
#indeed
The sqlfiddle link still hasn't opened for me, though hasn't timed out either, so there's hope still
 
@AJ Thanks
 
10:49 AM
Sorry, had to attend to an issue at work.
 
A J
@AndriyM What do you saY?
@AndriyM Ah. No problem.
 
Actually I think it should be possible to generate the transaction row with a trigger while updating the balance in the user table if you also agree to introduce a balance_last_updated timestamp to the user table (so it could be used in the trigger to populate the timestamp in the transaction row).
 
A J
Wouldn't using trigger create a problem if another Transaction runs for a different user at the same time?
 
For a different user, no, it's concurrent updates of the same user's balance that I'm less certain about.
 
A J
ohh
 
10:54 AM
Although with the serialised isolation level that shouldn't be a problem, I'd think
 
A J
hmm
So, I don't have to use a subquery? Just create a trigger to update two tables in one query?
 
triggers trigger me
 
A J
Huh?
 
@AJ I'm trying to whip up an example, but please keep in mind that I'm not sure how well this approach is going to work for you in the long run. Off the top of my head, one way it may not work is if you decide to add more columns to the transaction table that would have no counterpart in the user table but would need to be populated nevertheless.
 
A J
That's a minimal table structure I have posted.
There would be more columns in both tables.
 
11:09 AM
Well, there goes my idea then :)
Anyway, FWIW: dbfiddle.uk/…
 
A J
@AndriyM Thanks for this work. I am sure I can find a way to incorporate it into my code. If there is any issue, it will come out during load testing.
I am not sure how to ask this question on the main site without getting it closed as a duplicate of question Paul linked or POB.
 
@AJ Looks good. You have a single table that stores transactions and balance. Good. I would try to implement A-K answer in the linked question above. MySQL 8 has both FK and CHECK constraints.
 
Your question isn't about creating a schema, you already have one. If I understand correctly, you are asking how to populate the previous and update balance values at the time of inserting a transaction row.
 
@ypercubeᵀᴹ Yes Alex Kuznetsov's pattern is a favourite of mine.
 
And I would use no triggers at all. The INSERT statements should take care of the details.
@PaulWhitesaysGoFundMonica Yeah, I quite like it. And have used in practice.
 
@ypercubeᵀᴹ ☝️this guy gets it
 
@ypercubeᵀᴹ I think the trigger may still be needed to populate the current balance in the user table.
 
The really good about it is that you do not update the table. One only inserts new transactions.
@AndriyM You could use a trigger, yes. Or not. I just don't like them.
 
A J
@ypercubeᵀᴹ I see two tables. One for transactions and one for maintaining the main balance.
 
@AJ Ah, I didn't notice there was a balance in the users table. Consider getting rid of that column ;)
 
11:24 AM
A trigger isn't the only option, I agree. It depends on the requirements I guess. You could update the balances on a schedule with a cron job (or whatever it's called in MySQL)
 
A J
@ypercubeᵀᴹ Suppose I have to get the current balance of a user, then I should be fetching the last row in the transactions table for a particular user every time. Wouldn't it be a little heavier? Because there's gonna be thousands of records in the transaction table and only a few hundred users.
 
@AJ No, not really. A good index on (user_id, some_column) would take care of it.
 
A J
I will be showing a user's current balance that will automatically be refreshed every few seconds. There will be transactions carried out by users, parent users and the system.
@ypercubeᵀᴹ Only indexing will be on user_id
 
11:38 AM
Even better for MySQL: 0 indexes besides the PK. Just make (user_id, id) your PK. If you want to strongly enforce the constraints (as in A-K schema), you'll need a few indexes for sure.
Well no, I was wrong above. You'll still need an index on (id) for the AUTO_INCREMENT to work in InnoDB engine.
 
A J
@ypercubeᵀᴹ yep
Do you know you answered my question once on DBA?
I just recalled your name.
 
That must be from back when you asked questions on site instead of in chat. Good times.
 
Really? Which one?
 
A J
@PaulWhitesaysGoFundMonica Well, I was a newbie back then. :P
@ypercubeᵀᴹ This one.
 
11:56 AM
@AJ You're still a newbie 😋
 
A J
@PaulWhitesaysGoFundMonica Do I have a New Contributor badge? ;P
 
@PaulWhitesaysGoFundMonica hahah
And when I ask on main they get discussed in chat.
Strange world.
 
@AJ 👋🏼 New Contributor 👋🏼
 
A J
Discussing here actually will help me formulate my question, which I will ask tomorrow.
 
Tim
12:19 PM
Hi, Is Cassandra the most advanced database system?
Is it still in favor as it was a few years ago?
What other database systems are advanced or in favor, besides or if not Casandra?
 
Tim
I am asking if cassandra is still in favor and advanced nowadays, and what database systems are in favor nowadays if not cassandra
 
For what it's worth, Cassandra never fell out of favour with me
 
Never heard of it 😀
2
 
Tim
@AndriyM What other database systems are in your favor?
 
12:26 PM
@Tim "the most advanced"? It never was ;)
 
@Tim SQL Server is the only DBMS I've ever actually worked with, so it's my only favourite by default. I might like PostgreSQL too, but as I said, no working experience.
 
Tim
@ypercubeᵀᴹ do you have more to say
@AndriyM how "Cassandra never fell out of favour with me"?
 
I am about to leave so maybe later.
 
Tim
Am I in the wrong place to ask the questions?
 
@Tim Well, it couldn't because it never became a favourite of mine to begin with. Sorry, that was misleading of course, and deliberate too, but I didn't mean to offend or upset
 
Tim
12:30 PM
I saw the main site has above 100 questions under Cassandra, so I overestimate its popularity
 
It's far from being one of the most popular ones on the main, that's for sure.
 
Apache Cassandra is a free and open-source, distributed, wide column store, NoSQL database management system designed to handle large amounts of data across many commodity servers, providing high availability with no single point of failure. Cassandra offers robust support for clusters spanning multiple datacenters, with asynchronous masterless replication allowing low latency operations for all clients. == History == Avinash Lakshman, one of the authors of Amazon's Dynamo, and Prashant Malik initially developed Cassandra at Facebook to power the Facebook inbox search feature. Facebook released...
 
A J
Does it look good?
 
Aside from all the "gonna"s, yeah
 
Cassandra is #10 🤷‍♂️
#1 in class though
 
12:37 PM
Oracle is spam
 
A J
@PaulWhitesaysGoFundMonica "gonna"?
 
@PeterVandivier Ah, so "the most advanced" may still be warranted, it just need to be qualified a little
 
well... most popular at least
 
"Most advanced in its class"
 
12:39 PM
> Most advanced #10 ranked NoSQL dbms
It does have a nice logo
 
A J
@PaulWhitesaysGoFundMonica ok. Posting it in a few minutes.
 
@PaulWhitesaysGoFundMonica according to bing
 
A J
@PaulWhitesaysGoFundMonica Is the title good?
 
@AJ Don't expect any up votes. They doubled in value recently so I always award half an up vote, which gets rounded down.
 
A J
I don't and wouldn't.
 
12:41 PM
@AJ Looks fine to me
If it reflects the core of the question sufficiently, that is
 
@AJ You should mention if the tables will only ever have inserts, or if update/delete is possible.
> Synchronizing transactions and account balance
 
A J
??
 
Perhaps Paul is asking whether you expect past transaction rows to be updated/deleted
 
Yes I am asking if the tables will only ever have inserts.
The quote was a suggested title
 
A J
ok
0
Q: How to write SQL queries to populate the tables while synchronizing transactions and account balance?

A JI have two tables having the following schema. CREATE TABLE users( `id` INT AUTO_INCREMENT, `balance` DECIMAL(10, 2), PRIMARY KEY(`id`) ); CREATE TABLE user_transactions( `id` INT AUTO_INCREMENT, `user_id` INT, `previous_balance` DECIMAL(10,2) COMMENT 'Balance before transaction', ...

Done. Not sure about the tags.
 
1:11 PM
i'm pretty tickled that 3 people have answered after me on that sa login failed question and all 3 answers are softball rephrasing me
makes me feel real good
maybe if they could react with emoji instead of upvotes or downvotes, i'd get some appreciation
 
Straightforward as it gets
 
Comes off as snarky. Answer would be better without it.
 
> That log message is as straightforward as it gets.
 
1:15 PM
🤷‍♂️
it's not mean, and it's not meant to be mean
 
@PeterVandivier aaaahhhh, but....
 
I can only tell you how it reads to me
 
oh lawdy
here i go offendin' people agin
 
1:58 PM
Sounds like unwelcoming behavior. What is this, Stack Overflow?
 
Evan's been absent lately, and the channel needs a troll. I stepped up.
 
@PeterVandivier PETER THE GREAT SUBSTITUTE
 
IT IS I
PETER THE MEDIOCRE
 
Peter The Van Driver
6
 
that is the First Time i've ever seen that pun
💯
 
2:12 PM
This is Abhishek Mishra
3
 
This place may have some vandivy people and Peter is one of the Vandivier ones.
6
 
2:26 PM
Well that petered out quickly
6
 
AI?
 
 
3 hours later…
5:23 PM
0
Q: Right way to create index organized table

parladI am trying to create a index organized table in oracle 11. I create the index organized table and insert the row from another table. create table salIOT ( mypk , cid , date, CONSTRAINT sal_pk PRIMARY KEY (mypk) ) ORGANIZATION INDEX AS Select * from another table; But the leaf blocks are emp...

Why was ^ migrated to SO? Looks like a legit DBA question.
 
Perhaps there is a clue there somewhere 🔎
I don't know why the OP flagged to ask for it to be migrated, but they did.
Given that they could have simply deleted the question, and reasked there, I saw no reason to decline their request.
 
I don't see that comment
 
Well that would explain your question then. Try refreshing the page?
Oh I see you're looking at Stack Overflow
Try that one.
 
that's what happens when I click on the question -- it sends me to SO
some weird redirection -- I click on the dba.se URL and end up on SO
 
That last one has a noredirect
 
5:32 PM
no it doesn't
 
well, may be it does, but I get redirected anyway
 
one box being helpful
let me try this one more time
 
this one does work
 
5:34 PM
no need to threaten me though
 
I wasn't. I was getting frustrated with this web site being super helpful with my links.
When I threaten people I use knife and gun emoji.
 
ah well then, I'll see myself out
 
 
1 hour later…
6:59 PM
0
A: High RAM memory usage

Max VernonIn general, you want to utilize as much RAM as possible (leaving enough for the O/S, etc), since that means data is in-memory instead of being on disk. For a CRM system serving 100 people, you may find 16GB of RAM dedicated to the server is not enough. My phone has 8GB of RAM, for instance, a...

Tom Tom is that you?
2
 
7:15 PM
@PaulWhitesaysGoFundMonica you're quite Santa's lil helper, aren't you? :))
 
7:31 PM
in other news, downvotes cost nothing people. If you see something terrible, downvote it!
3
 
On questions, yeah
 
8:13 PM
yah, forgot to mention that bit!
 
9:02 PM
Yes, we need to access SQL Server on internet — Mohammad Dayyan 2 hours ago
Press F to pay respects
@MaxVernon ☝🏻 can I downvoted that comment? It’s pretty terrible
 
9:36 PM
Seems like good advice to me
 

« first day (3250 days earlier)      last day (1618 days later) »