Storing money in MySQL (the right way)

  Рет қаралды 41,844

PlanetScale

PlanetScale

Күн бұрын

📚 Learn more about PlanetScale at planetscale.co....
------------------
01:15 Creating the money table
02:27 The problem with floating points
03:12 Remaking the table with decimals
04:14 Storing money as integers
05:12 Remaking the table with integers
------------------
💬 Follow PlanetScale on social media
• Twitter: / planetscaledata
• Discord: / discord
• TikTok: / planetscale
• Twitch: / planetscale
• LinkedIn: / planetscale

Пікірлер: 174
@ucretsiztakipci6612
@ucretsiztakipci6612 Жыл бұрын
You are an excellent teacher. Knowing or being expertise on something is something but ability of teaching it very simple and alligent is beyond that. Great content, I learnt a new thing today!
@PlanetScale
@PlanetScale Жыл бұрын
That's incredibly kind of you. Thank you!
@ucretsiztakipci6612
@ucretsiztakipci6612 Жыл бұрын
@@PlanetScale it's the reality. Thanks to your effort, PlanetScale is lucky to have you. Greeetings from Istanbul.
@andrezimpel_unknown
@andrezimpel_unknown Жыл бұрын
I also hope to see more videos explained by him. :)
@ronsijm
@ronsijm 10 ай бұрын
There are comments saying "YOU SHOULD ALWAYS STORE MONETARY VALUES IN CENTS" - and it's also mentioned here in the video, but it depends on the situation. Just "Normal billing", yea, sure, that's fine. But I've worked on core banking applications, and in the financial industry cent precision is not really good enough, and we usually use a decimal precision of 4 or 6. Like imagine you're doing Index Investing - you might have 0.01% of a specific stock that rises 1% that day. You only gain $0.009 on that specific stock, but you have 10 million of those kinda stocks in your portfolio. That's 90k you don't see. Then if you check your generated reporting every day, you'll get very weird spikes and dips when things wobble between $0.009 and $0.01
@Farbfilmstudio
@Farbfilmstudio 8 ай бұрын
in that case store it as micro cents
@Murv
@Murv 3 ай бұрын
Always still store it as an integer, otherwise you'll get unprecise, which is even worse in banking :)
@RealAshleyBailey
@RealAshleyBailey Жыл бұрын
I want to take this one step further and say, YOU SHOULD ALWAYS STORE MONETARY VALUES IN CENTS, every company I know of, Stripe, Square and others, all store there values in cents in the backend, it is the most accurate and precise way to do calculations, especially when your doing currency conversions. EDIT: I wrote this comment before watching the end of the video.
@IamI16
@IamI16 Жыл бұрын
I'm a newbie in database design. Does that mean I should use the integer method instead of the decimal one when dealing with the MONETARY values?
@niz11
@niz11 Жыл бұрын
​@@IamI16i think you should store it as integer. This however has to be decided when you design your application. Think about the smallest possible denomination too. If your smallest possible value is 1 cent, then simply converting monetary values to integer by multiplying it with 100 works fine. So $1 will be stored as 100 in the database. But if your application smallest denomination value can be half of a cent or 1/10 of a cent, then you might want to consider multiplying the monetary value by 1000, that is 1 = 0.1 cent. So a dollar will be stored as 1000 in the database.
@nedjed4811
@nedjed4811 Жыл бұрын
​ @niz11 example show why you should NEVER store monetary values in cents. If your business considers that the precision should be limited to cents, yes it would work and would be even better. But if one day the business change, and you want more precision, what is your solution ? Change that implict rules of what this integer represent ? Then you will need to go through a data migration, and code update. And if your business goes international with currency using more precision, you must adapt you whole codebase / data structure for them (a customer would not like to see its balance on your app fluctuate with dollar FX rate, so convertion to dollar is not an option)
@CarlosPaleodaRocha
@CarlosPaleodaRocha Жыл бұрын
What if you are a store which sold a product priced at $ 100 in 3 equal instalments? Each would be registered as $ 33.33 which would sum up as $ 99.99 and not original $ 100. You would have to work this around too...
@RealAshleyBailey
@RealAshleyBailey Жыл бұрын
@@CarlosPaleodaRocha Any software you build should be able to either mark installments as $34, $33, $33 or choose to only charge up to the $99.99, most businesses would chose to forgo the 1 pence because it really isn't a big deal
@nerdus8388
@nerdus8388 Жыл бұрын
You're a very good teacher. I really like your way of teaching stuff. Keep the good work up.
@PlanetScale
@PlanetScale Жыл бұрын
Thank you! 😃
@gosnooky
@gosnooky Жыл бұрын
I recommend the INT values if using multiple currencies. Some currencies like the Vietnamese Dong (haha), don't have "sub unit" values, as 1 VND equals 0.000042 USD. It then allows the application side to properly apply currency functions and formatting.
@PlanetScale
@PlanetScale Жыл бұрын
Totally! You can see that explanation at 04:52
@acasualviewer5861
@acasualviewer5861 9 ай бұрын
Yeah I've used this when dealing with multiple currencies.. then you can use a scaling factor. Though dealing with conversions such as what you present here could be challenging since 0.000042 USD is not representable in cents.
@pleggli
@pleggli Жыл бұрын
Working with cents as an integer is fine until you suddenly need exact fractions of cents for any reason. Exact decimal types are slower but you can always change the precision at any time in the database and even set it to infinite.
@zeteya
@zeteya 11 ай бұрын
Just times all the values by 10 or 100 or whatever then, same thing for decimal.
@pleggli
@pleggli 11 ай бұрын
@@zeteya what do you mean?
@pleggli
@pleggli 11 ай бұрын
@@zeteya If you already have a running program that uses cents and suddenly need a few extra decimals you would have to rewrite a bunch of code and migrate all the data in database by multiplication and you have to do that every time you need to represent a smaller number which is just a waste of time and an unnecessary potential source of bugs. There are very few good reasons for not using a data type that is actually made for precise decimal representation.
@zeteya
@zeteya 11 ай бұрын
@@pleggli Just don't change your database then, change your app logic, the decimal precision is there already.
@pleggli
@pleggli 11 ай бұрын
@@zeteya if you use cents as an integer in your database you can never get higher precision than a cent. You need to use it both in the logic and in the database to be able to store and do calculations with and display it correctly to your customers.
@williamchiarato
@williamchiarato Жыл бұрын
Excellent video. I'm experiencing a situation in my new job just like you described in the video. The old system, made in PHP, is used to store monetary values and has a lot of problems because the previous developer was using doubles. The system never calculates the values correctly, it always misses a few cents.
@Guitarrob83
@Guitarrob83 Жыл бұрын
lol
@hacktor_92
@hacktor_92 10 ай бұрын
php and floats? that's a big no-no. they're weirdly implemented and has different precision depending on cpu architecture. this comes from a background where i had to sum up how many hours someone worked, some division and stuff like that. it's horrible.
@tipeon
@tipeon Жыл бұрын
This happened to a colleague of mine. He was developing some kind of report, and the boss was giving him a hard time because his totals were wrong. The colleague was a decent developer, but not very detail-oriented. And the boss was and ex-accountant. They were unable to find the cause until I pointed it out.
@011sale
@011sale 11 ай бұрын
This channel is a gem.
@Tony-dp1rl
@Tony-dp1rl Жыл бұрын
I agree in terms of Tables, but not always for Views where business logic may be dividing/distributing values. You don't want $100 / 3 to be $33.33 and only $99.99 when the three values are added back up in a report - unless you have an offshore account to put the extra cent in.
@neehgurg2111
@neehgurg2111 Жыл бұрын
well... what should $100 / 3 be equal to instead...?
@chilversc
@chilversc 11 ай бұрын
​@@neehgurg2111generally, 33.33, 33.33, 33.34. The extra cent has to go somewhere.
@Tresla
@Tresla 11 ай бұрын
Your business logic should handle such cases and become $33.33, $33.33 and $33.34. You shouldn't just blindly divide monetary values without accounting for any remainder.
@JabariHunt
@JabariHunt 10 ай бұрын
😂
@acasualviewer5861
@acasualviewer5861 9 ай бұрын
when dealing with multiple currencies, I've used the integer technique and you can a scaling factor like 100 for USD, or 1 for currencies that don't have cents.
@ardiansyahrukua3020
@ardiansyahrukua3020 6 ай бұрын
Bro, you save me from the trouble I would make in the future. Super thanks from Indonesia :>
@fullhalfadder
@fullhalfadder 8 ай бұрын
I worked at a company that had hundreds of thousands of dollars running through it every day and it was storying everything as floats. We had no idea how inaccurate our data was or how much money we lost or left on the table because of this error. What was crazier was that the devs there refused to acknowledge this was a problem and fix it.
@ahmad-murery
@ahmad-murery Жыл бұрын
I once worked on a project that uses DOUBLE for currency and it was very painful for the same reason you mentioned here. Thank Aaron!
@TheMoonWatcher
@TheMoonWatcher 10 ай бұрын
I wish I heard this advice like 8 years ago when I was first starting to work on a system that heavily does money-related calculations 😂 Some data already existed when I joined, but I might have been able to migrate the data at that point to use integers only. I can't count how many times we have had to format to 2 decimals on both the front-end and the back-end when doing calculations because our calculations would be off by one or more cents due to rounding errors 😂 And just now I had to do a report in MySQL only... It took me a little while to fix the rounding errors when multiplying numbers together to get the same results as we do on the front-end. I think it is definitely much better to only work with integers, this is great advice!
@PlanetScale
@PlanetScale 10 ай бұрын
Oh this pains me 😭 Sorry you had to deal with all that
@TheMoonWatcher
@TheMoonWatcher 10 ай бұрын
@@PlanetScale thanks! With the healing power of time, looking for the missing few cents was kind of fun 😂
@ryanqvincent144
@ryanqvincent144 8 ай бұрын
@@TheMoonWatcher Been there: It wasn't fun but it was a very valuable lesson in 'rounding errors' and how 'picky' Accountants are. ;-/ It was a valuable lesson.
@kid_kulafu_1727
@kid_kulafu_1727 3 ай бұрын
I subscribed. Thank you! easy to understand and no bullshido. arigato gozaimasu
@elbaraaabuaraki327
@elbaraaabuaraki327 8 ай бұрын
Completely agree, I ALWAYS use decimals for any financial value or anything needing accuracy
@paulezekiel-hart733
@paulezekiel-hart733 Жыл бұрын
Thank you sooo much, i'm behind my deadline and discovered this issues, the solutions you've provided will do perfectly
@CarlosPaleodaRocha
@CarlosPaleodaRocha Жыл бұрын
It only worked with decimal because you have set digits [decimal(10,2)] as if you didn't [using decimal without parenthesis info] it would only return 20 for each field. Also, if you set them as double(10,2) you will get correct result too. We cannot say it works with decimal and didnt with double when not using the same approach on both. Nothing against storing in cents, but it also may get you in trouble. Lets say you sold your product in 3 equal instalments and your product is sold at $ 100. It would store 3 instalments of $ 33.33, which would sum up as $ 99.99 and not your original $ 100
@klicer3068
@klicer3068 11 ай бұрын
Do you have a solution for the $99.9 problem? Other than checking if they have actually paid the full amount and asking for the remainder
@CarlosPaleodaRocha
@CarlosPaleodaRocha 11 ай бұрын
Hello @@klicer3068 , no I don't. I believe it doesn't matter which data type you choose, you will always end up by checking for that. My point was exactly this, you will ever have to check it.
@kevingood10
@kevingood10 6 ай бұрын
i store diff in first installment
@indramal
@indramal Жыл бұрын
I like this guy.
@JosepBernad
@JosepBernad 8 ай бұрын
A great Part 2 of this video would be explaining a strategy on how to handle multiple concurrencies! Thanks for the video!
@artemeelemann317
@artemeelemann317 11 ай бұрын
YourSQL videos are really useful 🙌
@JustSteveKing
@JustSteveKing 7 ай бұрын
I've been building apps with financial values for years. I just had a case where I wanted to store "salary" and knew Aaron recorded something so had to get his opinion!
@permanar_
@permanar_ 7 ай бұрын
I have dealing with this kind of data. We usually stored the value as cents or just simply store the value times whatever decimal you want it as be (and of course you should save/store this decimal value either on your database or just make some config for this). So for example there is $15 and I use 16 decimals, basically will store the data as 150000000000000000.
@calebcipra6795
@calebcipra6795 Жыл бұрын
Thanks for the video, I really appreciate it 💯
@abdulbasitrana2743
@abdulbasitrana2743 Жыл бұрын
Very Good Explanation. Keep it up.
@EngineeringVirus
@EngineeringVirus 11 ай бұрын
Woah i though of coming here and grab some of that money you stored inside those db. Going empty handed
@PlanetScale
@PlanetScale 11 ай бұрын
Ah shoot, sorry for the bamboozle. Check back next time!
@MSI2k
@MSI2k 9 ай бұрын
One exception to this rule is Oracle. Float and Double is stored in decimal representation
@melwinalm
@melwinalm 8 ай бұрын
Great explanation
@CoderClimber
@CoderClimber Жыл бұрын
my usual way of doing things, If want to calculate the value, use int decimal is relatively slower
@daethic421
@daethic421 8 ай бұрын
What is this code editor you are using? It looks very cool. Is it just something native to planetscale?
@lukejagodzinski
@lukejagodzinski 8 ай бұрын
I would even say that you should also use integers for other units like for example kilograms. And instead store it in grams or even smaller unit if need more precision. It will be easier to convert it to imperial system if you ever need that. And also all the benefits of summing values etc.
@FabianMendez
@FabianMendez 8 ай бұрын
I agree. I usually use cents ( € and $ ), then you just have to show in the unit that you want to the user on the frontend.
@berndeckenfels
@berndeckenfels 11 ай бұрын
Lots of financial math might deals with fraction cents, so using 3 decimals (*1000) is needed, or for some things like item prices even 4 or 5 decimals
@PlanetScale
@PlanetScale 11 ай бұрын
Absolutely! Very dependent on the domain requirements
@addanametocontinue
@addanametocontinue 8 ай бұрын
Sad to admit that I know of one company whose software targets accountants and they store monetary values as DOUBLE and every now and then clients complain that the results of their queries are inexplicably rounding or approximating values.
@wheresmyskin
@wheresmyskin 8 ай бұрын
Soooo.. Decimal and Big Decimal, right? Right? :D With integers you have to remember how places for "cents" to keep. Some currencies have 2, some have 3, there are currencies that have 0 decimal places. So you need additional value to know how many places you're using. Or to be safe you store 3 places, so you multiply by a 1000., so $20.55 becomes "20550". So you have floating point problem handled, what about rounding numbers? It gets tricky. Decimal type was designed for storing money in databases and I wouldn't use anything else.
@andy_lamax
@andy_lamax 8 ай бұрын
What if you are dealing with bitcoins (BTC)?? which datatype would you use??
@ko_tech
@ko_tech 9 ай бұрын
For money use integer or decimal, because that is optimal, float or double will get you in trouble.
@NedumEze
@NedumEze 10 ай бұрын
Wow! Thanks a lot
@yaybrianna
@yaybrianna Жыл бұрын
Wouldn't using an integer for cents ignore possible fractional cents?
@PlanetScale
@PlanetScale Жыл бұрын
You'd have to decide what the lowest unit you want to store is and adjust the conversion math appropriately.
@jayantrawat5961
@jayantrawat5961 Жыл бұрын
Great video. What do you personally prefer to use? I do love to use integers, as I have seen many big companies use this approach, like in your example Stripe
@PlanetScale
@PlanetScale Жыл бұрын
Personally (this is Aaron) I like to use decimals when working with USD only. If I was going to be storing multiple currencies, I'd probably go the Stripe route and store it as integers!
@Ropbastos
@Ropbastos Жыл бұрын
@@PlanetScale Why that differentiation?
@hacktor_92
@hacktor_92 10 ай бұрын
​@@Ropbastos i can do an educated guess on this one: it's simpler to calculate the currency exchange. there are currencies (like HUF) which are calculated as 100 HUF = 0.26 EUR, due to the fact that 1 HUF = 0.0026 EUR, so you'll have to constantly scale the decimal part constantly, i.e. from decimal(10,2) you'll have to alter to decimal(10,4), and so on, which may cause issues in some cases. this is also applies for Romania before the denomination of it's currency, when you had to multiply by a thousand every time.
@vinnylozada
@vinnylozada Жыл бұрын
What is the use case for using float or double? Is it to store numbers that would never be used in computations?
@PlanetScale
@PlanetScale Жыл бұрын
Great question, and truly... floating point numbers kind of blow my mind. You're right though, if you're doing computation and you need strict accuracy floating point won't work well. If you need huge ranges of values with varying precisions, then floating point is great. You could think of perhaps measurements, lat/lon (if you dont use point columns), or timings. Stuff like that might be a good case!
@acasualviewer5861
@acasualviewer5861 9 ай бұрын
They're useful for physics problems. For probabilities. For statistics.
@pcnerd5994
@pcnerd5994 7 ай бұрын
This problem is because of the conversion from decimal to binary and from binary to decimal. You can do this to any programing language 0.1 + 0.1 + 0.1 it's not equal to 0.3
@ukyo6195
@ukyo6195 8 ай бұрын
Simple use decimal(10,3)
@TravisTennies
@TravisTennies Жыл бұрын
Facts! ❤
@genstian
@genstian 11 ай бұрын
I almost always use the decimal for everything with a decimal point
@wfl-junior
@wfl-junior 8 ай бұрын
what are the use cases for floats and doubles, why not use decimals for everything?
@spicynoodle7419
@spicynoodle7419 Жыл бұрын
I stay away from decimal because they usually come as strings from the database and they overflow very fast
@JohanNordberg
@JohanNordberg Жыл бұрын
Interesting! I assume this is not unique to MySQL and this is also true for Postgres, SQL Server, etc?
@vytah
@vytah Жыл бұрын
It applies to every database and every programming language
@raghuveerdendukuri1762
@raghuveerdendukuri1762 6 ай бұрын
Always use decimal data type ingeneral
@Cyber_Lanka
@Cyber_Lanka Жыл бұрын
Nice video. What is the tool you are using to run queries?
@PlanetScale
@PlanetScale Жыл бұрын
TablePlus!
@AlexCastroDev
@AlexCastroDev 8 ай бұрын
I like to handle with cents, because i will not have problems with dynamic language
@aarforce
@aarforce Жыл бұрын
Great information, thank you! What is the interface you're using for writing those mySql queries?
@PlanetScale
@PlanetScale 11 ай бұрын
TablePlus!
@Conorstew
@Conorstew Жыл бұрын
Good stuff
@fairphoneuser9009
@fairphoneuser9009 11 ай бұрын
I'm in the IT field for decades now, and I still think floating point arithmetics are weird. They make sense for some special cases, but in general they are just WTF...
@PlanetScale
@PlanetScale 11 ай бұрын
Honestly I still barely understand them.
@ple7y
@ple7y Жыл бұрын
Any maybe give a try to libraries like MoneyPHP and dinero.js...
@ipelengmolete161
@ipelengmolete161 9 ай бұрын
At my last job, they stored currency as string. I don't want to talk about it.
@Ostap1974
@Ostap1974 9 ай бұрын
Just a quick note to audience -- if you are building multi0currency app, be aware that min denomination in different currencies may not be expected 0.01.
@xx-qj6sg
@xx-qj6sg Жыл бұрын
What application are you using?
@PlanetScale
@PlanetScale 11 ай бұрын
TablePlus!
@ThePaulMcBride
@ThePaulMcBride 11 ай бұрын
Are they glasses without lenses?
@user-bw6lh5xk2x
@user-bw6lh5xk2x 8 ай бұрын
What app are you using to make the queries?
@mrdeadrim310
@mrdeadrim310 10 ай бұрын
What if using it in varchar
@PlanetScale
@PlanetScale 10 ай бұрын
I wouldn't store money in a varchar! Tough to do math on at that point
@shravanuchil
@shravanuchil 11 ай бұрын
So what is the use of float or double? When to use them
@acasualviewer5861
@acasualviewer5861 9 ай бұрын
Float is for physics or math not currency. Where values are always approximate. So if you need to store the probability it is going to rain, you can use floats or doubles. Or the estimated demand, or things like that which are approximations to begin with. Though it is interesting to consider whether it's appropriate to use for an interest rate.
@tedma4
@tedma4 10 ай бұрын
Can you add a schema or interface to a JSONB field?
@PlanetScale
@PlanetScale 10 ай бұрын
You can actually
@babatundeadeleke5497
@babatundeadeleke5497 Жыл бұрын
In a multi-currency system, the number of decimal places might need to be stored too.
@PlanetScale
@PlanetScale 11 ай бұрын
Good point!
@dilanboskan2222
@dilanboskan2222 Жыл бұрын
How do you handle different types of currencies?
@PlanetScale
@PlanetScale Жыл бұрын
You could use integers and store the lowest denomination as a whole number, and then store the currency in a second column.
@sheivongamboa
@sheivongamboa 11 ай бұрын
so float(10,2) does the same thing as decimal(10,2) i have always use float(10,2)
@acasualviewer5861
@acasualviewer5861 9 ай бұрын
check. but decimal seems more correct.
@hassamulhaq7762
@hassamulhaq7762 11 ай бұрын
maybe other relates me that i often use string datatype for money.
@acasualviewer5861
@acasualviewer5861 9 ай бұрын
inefficient for massive computation.
@xdevchris
@xdevchris Жыл бұрын
What's the tool you are using here? thanks!
@PlanetScale
@PlanetScale Жыл бұрын
TablePlus!
@greatestuff
@greatestuff 8 ай бұрын
This dude's Hot Take is trying not to have Hot Takes! How dare he, let's get him! C'mon Internet!
@PlanetScale
@PlanetScale 8 ай бұрын
oh no
@elliejohnson2786
@elliejohnson2786 Жыл бұрын
I always store my money as strings because they'll be exactly as I enter them :D
@PlanetScale
@PlanetScale Жыл бұрын
Hard to do math on them then!
@IvanRandomDude
@IvanRandomDude Жыл бұрын
Great, please send me 10bc0 dollars.
@devhammed
@devhammed 11 ай бұрын
@@PlanetScale I usually store as XXX LOWEST_UNIT_INT e.g " USD100" represents $1. Now in the Laravel side, there is cast so I create a cast class that will use the string to create a Money PHP object and when storing back, it will store it accordingly as STRING. In the database side, I use CAST function on the column to convert to signed integer for that particular while using REPLACE to remove the currency code. $columnCast = sprintf( 'CAST(REPLACE(%s, "%s", "") AS SIGNED)', $column, $currency->getCurrency(), ); Instead of repeating that logic, I also created a "whereMoney" Eloquent Builder macro that can compare exact value, greater than, less than and range.
@this_is_mac
@this_is_mac Жыл бұрын
What if you want to divide the money with some value?
@vytah
@vytah Жыл бұрын
It all depends on what you want to do with fractions of a penny. You usually want to round in a way your accounting department tells you to.
@tipeon
@tipeon Жыл бұрын
Not only the accounting department, the laws of the country also dictate the rounding rules. Now you can imagine how developing an international accounting software can become a nightmare. 😂
@_alexlazar_
@_alexlazar_ Жыл бұрын
Storing in int in the smallest denominator (cents, wei, etc) is something very common in blockchain apps. I thought it was only a crypto world thing and not a thing in other languages/environments tbh, this is very interesting to find out and see.
@SenjaiYT
@SenjaiYT 11 ай бұрын
What editor is this?
@PlanetScale
@PlanetScale 11 ай бұрын
Table Plus
@SenjaiYT
@SenjaiYT 11 ай бұрын
@@PlanetScaleThank you! Looks like a clean alternative to datagrip. Much appreciated.
@gerakore8948
@gerakore8948 Жыл бұрын
how else am i supposed to shave off the rounded bits then?
@PlanetScale
@PlanetScale Жыл бұрын
"I'm just talking about fractions of a penny here"
@patfre
@patfre 11 ай бұрын
What about the money type? That’s a thing lol so it’s probably the better way to do things
@PlanetScale
@PlanetScale 11 ай бұрын
Can you kindly point me to the money type in the MySQL documentation? If it exists I'm truly not aware of it.
@RaicaBogdan
@RaicaBogdan 9 ай бұрын
decimals! 😀
@PlanetScale
@PlanetScale 9 ай бұрын
Spoiler alert!
@RaicaBogdan
@RaicaBogdan 9 ай бұрын
@@PlanetScale oops 😬
@mqst
@mqst 10 ай бұрын
Use decimal.
@PlanetScale
@PlanetScale 10 ай бұрын
Spoiler alert
@mqst
@mqst 10 ай бұрын
​@@PlanetScale:D
@lloydjoseph1300
@lloydjoseph1300 6 ай бұрын
He kept being passed the ball. The other 4 should make sure not to pass to the idiot. Passing to him is the same as throwing away the possession.
@S1S2S3S4
@S1S2S3S4 11 ай бұрын
Imagine not having MONEY type
@PlanetScale
@PlanetScale 11 ай бұрын
I don't have to imagine it, I live it every day!
@AndreasPetersson
@AndreasPetersson 8 ай бұрын
everything you say makes sense until you start working with cryptocurrency. integer cent values don't make sense for any cryptocurrency - 8 18 or sometimes even 256 decimal places are common. in this case you will run into limitations even with decimal. in this case i'd recommend using strings as a fallback or using a DB that supports this precision natively (postgres)
@PlanetScale
@PlanetScale 8 ай бұрын
Oh yeah, I can't speak to crypto at all. Also isn't all that stored on the Blockchain? What's it doing in a MySQL database?
@AndreasPetersson
@AndreasPetersson 8 ай бұрын
@@PlanetScale A blockchain is just a DB with weird write semantics :) Serious reply: most app specific backends need to mirror operations happening on blockchain, either to accumulate operations, enable efficient querying, store TX to broadcast.. the list goes on, there are many reasons to mirror a very small subset of a blockchain on a classic DB.
@jlhjlh
@jlhjlh 7 ай бұрын
Let's not exaggerate things. Many real world systems use doubles for financial data and it's really just fine. Unless you're a bank where extreme precision is important, it won't matter. If at the end of the year some random sum is off by 5 cents, then nobody cares and it's not an issue (ask accounting!). Using integers is much more error prone and using decimals is unfortunately poorly supported by many programming languages, so sometimes doubles is an okay choice. Of course, YMMV.
@joeljordan2718
@joeljordan2718 Жыл бұрын
'Promo SM'
@logicalsparrow2130
@logicalsparrow2130 Жыл бұрын
Integers will fail in the case of cryptocurrencies like Bitcoin, which needs at least 6 decimal places to convert to pennies and may need more in the future.
@medilies
@medilies Жыл бұрын
Saved 💾
Faster database indexes (straight from the docs)
13:28
PlanetScale
Рет қаралды 126 М.
WORLD'S SHORTEST WOMAN
00:58
Stokes Twins
Рет қаралды 185 МЛН
Дай лучше сестре 🤗 #aminkavitaminka #aminokka #сестра
00:15
Аминка Витаминка
Рет қаралды 646 М.
а ты любишь париться?
00:41
KATYA KLON LIFE
Рет қаралды 2,6 МЛН
SCHOOLBOY. Последняя часть🤓
00:15
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 12 МЛН
I loaded 100,000,000 rows into MySQL (fast)
18:27
PlanetScale
Рет қаралды 177 М.
You don't need NoSQL (use MySQL)
31:26
PlanetScale
Рет қаралды 74 М.
How I Deploy ALL My Apps - My 2023 Stack
7:27
Theo - t3․gg
Рет қаралды 88 М.
From Idea To Robust Database Design
16:21
Ljupche Vasilev
Рет қаралды 8 М.
Pagination in MySQL - offset vs. cursor
13:20
PlanetScale
Рет қаралды 56 М.
SQL WITH Statements (Common Table Expressions - CTE)
5:40
Becoming a Data Scientist
Рет қаралды 96 М.
RAND is too slow (in MySQL)
17:32
PlanetScale
Рет қаралды 13 М.
Easy database indexing strategies
36:03
PlanetScale
Рет қаралды 24 М.
Working with time series data in MySQL
20:35
PlanetScale
Рет қаралды 21 М.
This is why understanding database concurrency control is important
9:05
📱магазин техники в 2014 vs 2024
0:41
djetics
Рет қаралды 934 М.
Опасность фирменной зарядки Apple
0:57
SuperCrastan
Рет қаралды 13 МЛН
На что способен ваш компьютер?
0:34