News for hackers. Stuff that matters.
Re:Why SQLite succeeded as a database (2016) by bob1029 on Wednesday February 19, 2020 @02:04PM (#22368841)
SQLite is a wonderful database. We use it in production many times over for all of our clients. Not having to worry about whatever arbitrary SQL Server installation is available in a particular environment has saved us so much time and frustration. Combine SQLite with .NET Self-Contained Deployments means that we (our automated tools) now copy our software distribution zip to target, extract to path, run executable as administrator and walk away. Without SQLite we could not do this.

Migrations are also hilariously easy with SQLite if you use the user_version pragma. We have a monotonically-incrementing number to indicate each version. Our migrator first queries this upon startup and runs all the migrations that exist between current user_version and whatever our highest sequence # is (defined as a constant in code). Some might argue that you should just use EF (or whatever language-specific ORM), but I prefer the level of control and the substantial performance boost you get with raw SQL and a simple migrator approach. I cannot speak for EF Core, but EF6 performance was absolutely abysmal in some more complex cases.

I would also say that performance might surprise you if you turn on WAL. I have saturated NVMe disks inserting lots of data into SQLite. The trick is to use a single connection and let SQLite handle the serialization for you, rather than try to manage multiple connections to the same file in code (i.e. one connection per logical operation sucks for SQLite).

Re:Why SQLite succeeded as a database (2016) by GordonS on Wednesday February 19, 2020 @05:56PM (#22370997)
I've been using SQLite for something like 20 years - how did I not know about `user_version` until now?!

I've always added a `schema_version` table with a single row containing a single column with the version, so thanks for letting me know about this!

Re:Why SQLite succeeded as a database (2016) by scottlamb on Wednesday February 19, 2020 @06:07PM (#22371095)
I didn't know about user_version or application_id either until just now. I think I'll start setting application_id. Probably not registering it in the SQLite repository - there's no procedure to do that at the top of the file and it looks like almost no one does. I'll just pick a random 32-bit int and assume I don't collide.

I don't think I'll use user_version though. I prefer my current solution: a version table with multiple rows. One for initial installation and one for each schema upgrade with timestamps and the software version that performed the operation. The current version is just the max. If my migration procedure goes badly, I have some clue what happened.

If my application supported schema downgrades, I'd want to have a separate operation_id and schema_version; the max operation_id would win rather than the max schema_version.

Re:Why SQLite succeeded as a database (2016) by int_19h on Thursday February 20, 2020 @10:45PM (#22380787)
application_id is really meant for scenarios where the SQLite database is treated as a document - a file that is intended to be copied around by the user, and opened by the same or another app elsewhere.

According to their mailing list, the way to register your own ID is to submit a patch that adds your ID to the file.

Re:Why SQLite succeeded as a database (2016) by zzo38computer on Friday February 21, 2020 @02:23AM (#22381490)
I tried to do that, but maybe the message didn't go through.

Some of the application IDs are made up using hexadecimal (such as Fossil), and some using ASCII (everything else listed in the magic.txt file in the SQLite repository). I have used base thirty-six; I later saw RADIX-50 mentioned, which would be another way.

Re:Why SQLite succeeded as a database (2016) by plq on Thursday February 20, 2020 @05:04AM (#22373964)
We also do something very similar but our version table has two columns: module_name and version. Instead of doing central schema management like in a usual monolith, Every module manages its own schema.
Re:Why SQLite succeeded as a database (2016) by api on Wednesday February 19, 2020 @02:25PM (#22369054)
I came here to say this. It succeeded because it's an extraordinarily high quality piece of code!

The 'lite' is even a bit of a misnomer. Properly tuned I've seen 1TB+ SQLite databases work just fine. It doesn't scale horizontally with CPU cores as well as a "real" database but it can perform very well with large data sets if there's only one or two writers.

Re:Why SQLite succeeded as a database (2016) by nbevans on Wednesday February 19, 2020 @03:52PM (#22369929)
There is actually no "lite" word in SQLite. Think of it as SQL-ite. The "ite" is a deliberate connotation to rocks/geology i.e. granite, magnetite, etc. Make of that what you will. This is documented BTW on the SQLite docs.
Re:Why SQLite succeeded as a database (2016) by spondyl on Wednesday February 19, 2020 @04:15PM (#22370144)
While I couldn't find anything in the docs, there's a snippet of a transcript here: https://changelog.com/podcast/201#transcript-67
Re:Why SQLite succeeded as a database (2016) by kohtatsu on Wednesday February 19, 2020 @04:59PM (#22370540)
Another: http://sqlite.1065341.n5.nabble.com/SQLite-Pronunciation-td8...

>[...] I think it should be pronounced "S-Q-L-ite". Like a mineral. But I'm cool with y'all pronouncing it any way you want. :-)

Re:Why SQLite succeeded as a database (2016) by StreamBright on Wednesday February 19, 2020 @02:27PM (#22369073)
What is the underlying storage structure that scales to TB+?
Re:Why SQLite succeeded as a database (2016) by pjscott on Wednesday February 19, 2020 @02:34PM (#22369150)
Just regular B-trees for row and index storage. There's a reason why it's such a popular data structure!

https://www.sqlite.org/arch.html

Re:Why SQLite succeeded as a database (2016) by v64 on Wednesday February 19, 2020 @06:00PM (#22371039)
Not to mention many filesystems are implemented as B-trees.
Re:Why SQLite succeeded as a database (2016) by bob1029 on Wednesday February 19, 2020 @02:36PM (#22369164)
If you want TB+, you are talking about multiple computers (in context of indefinite scaling).

For most who browse HN that immediately means you reach for Postgres (and you would be wise to do so), but I would argue you can continue to use SQLite indefinitely (one instance per node) if you manage replication and transactions between nodes at your application layer.

I realize this is probably beyond what most developers want to screw with, but I have seen some extremely promising results in experimental implementations of this scheme. Being able to replicate items conditionally based directly on business needs is a very powerful capability on paper - E.g. User session data must be synchronously replicated to all nodes, while other entities can by asynchronously replicated based on their use cases. You could handle replication and transactions based upon any business factor or state if you go down this path.

Re:Why SQLite succeeded as a database (2016) by chaz6 on Wednesday February 19, 2020 @03:56PM (#22369954)
There is a derivative called rqlite which uses the raft consensus protocol to give you a highly fault-tolerant distributed database.

https://github.com/rqlite/rqlite

Re:Why SQLite succeeded as a database (2016) by senderista on Wednesday February 19, 2020 @05:33PM (#22370830)
It’s a great idea and I’m working on something similar, but Raft or any other quorum-based consensus protocol is a poor fit for the data plane.
Re:Why SQLite succeeded as a database (2016) by antoinealb on Wednesday February 19, 2020 @06:04PM (#22371071)
Can you expand on why you think this is a poor fit ? Is this because of added latency due to the multiple round trip involved ?
Re:Why SQLite succeeded as a database (2016) by senderista on Thursday February 20, 2020 @12:55AM (#22373026)
It’s not latency, it’s throughput. Broadcast and incast network communication patterns in the LAN kill throughput, and are present in any quorum protocol. Atomic broadcast protocols like chain replication or LCR which use strictly sequential communication patterns (via chain or ring topologies) have much better throughput in LAN environments than Paxos/Raft (except for Ring Paxos, which requires IP multicast). In addition, because they outsource group membership and failure detection to a separate (likely Paxos-based) service, they require only f+1 members to tolerate f faults, rather than 2f+1 (see Lamport et al’s Vertical Paxos work). But they have two main downsides relative to Paxos/Raft-like protocols: latency grows linearly with cluster size and is bounded below by the slowest node (so they aren’t a good fit for high-latency WANs), and as noted above, they can’t “self-host” like Paxos/Raft.

PS Apparently my previous comment outraged the HN hive mind, judging by downvotes. I find this hilarious and revealing given that all I’ve said is obvious to any actual distsys researcher (ask eg the HyperDex or FawnKV folks about why they chose CR instead of Paxos). And at one large cloud provider I worked at, this was taken for granted back in 2012. Apparently “distsys” pop culture has yet to catch up.

Re:Why SQLite succeeded as a database (2016) by senderista on Thursday February 20, 2020 @01:15AM (#22373084)
I should also mention that a great virtue of quorum-based protocols (for majority or basic read/write quorum systems) is their ability to mask tail latency/transient faults. That is difficult to replicate in sequential protocols and is a good reason to use quorum protocols in high/variable-latency and otherwise unreliable environments like geo-distributed databases.
Re:Why SQLite succeeded as a database (2016) by Xorlev on Wednesday February 19, 2020 @10:54PM (#22372551)
Yes, please do expand on this, since fast Paxos and similar are used for this in mission critical distributed databases for exactly this use case.
Re:Why SQLite succeeded as a database (2016) by senderista on Thursday February 20, 2020 @01:04AM (#22373048)
I’m not sure how often Fast Paxos is really a good tradeoff, since in the LAN it has inferior throughput to the other protocols I mention below, while in the WAN >3/4 quorums expose you to additional tail latency, probably enough to negate the advantage of eliminating a single message delay if clients are distant from the cluster (see the Google SRE book for discussion).
Re:Why SQLite succeeded as a database (2016) by bawolff on Wednesday February 19, 2020 @08:35PM (#22372012)
At some point though, aren't you essentially reinventing a traditional db over top of sqlite?

The reason to use depencies is so you don't have to reinvent complicated wheels

Re:Why SQLite succeeded as a database (2016) by zmj on Wednesday February 19, 2020 @09:34PM (#22372239)
> Some might argue that you should just use EF (or whatever language-specific ORM), but I prefer the level of control and the substantial performance boost you get with raw SQL and a simple migrator approach.

Agreed. I wrote a performance-oriented lightweight ORM on top of SQLite calls: https://github.com/zmj/sqlite-fast . Its focus is minimizing allocations - treating SQLite as something closer to an in-memory store than a network API.

Re:Why SQLite succeeded as a database (2016) by to11mtm on Wednesday February 19, 2020 @05:17PM (#22370695)
>Some might argue that you should just use EF (or whatever language-specific ORM), but I prefer the level of control and the substantial performance boost you get with raw SQL and a simple migrator approach. I cannot speak for EF Core, but EF6 performance was absolutely abysmal in some more complex cases.

Look into Linq2Db [1] (Disclaimer, I contribute to the project a little bit.)

It's the perfect in-between for if you want LINQ like abstractions but don't want the overhead of an ORM, it's more like Dapper than, say, EF or NHibernate.

Best of both worlds: I can quickly prototype a design using SQLite, and then flip it over to SQL Server/Postgres by changing a config string.

EF Core is somewhat improved from EF in some ways (It's faster, often as fast as Linq2Db or Raw SQL) but has moved backwards in others (lots of stuff still doesn't work right, more importantly things that -used- to work in EF6). IMO EF Core tries to do too much; It tries to give the same API to interface with both Relational and KV stores, and results in not being great at either.

[1] https://github.com/linq2db/linq2db/

Re:Why SQLite succeeded as a database (2016) by bob1029 on Wednesday February 19, 2020 @05:53PM (#22370979)
We exclusively use Dapper for all database access. I have zero problems with a few string constants in my services that contain the requisite SQL statements for managing my business entities against the database. It's really nice having such a consolidated context where your SQLite implementations are just single partial classes tacked onto the services you are providing persistence for.

That is one other point - SQLite has enabled us to do some really deep consolidation of our codebase. We generally use one SQLite database per business entity or abstraction. Users.db, Logs.db, Sessions.db, Settings.db, etc. It allows for a truly 100% independent vertical stack (aside from coupling against business models) for purposes of developing various pieces of business functionality. This is, in my view, is the perfect ideal of 'microservice' architecture. One big folder called services, one class per 'microservice', one SQLite database per class, one collection of mappers per class, etc. I honestly feel like we have settled on the perfect grain for our codebase structure (at least in C#/.NET Core land). The benefit in our world is that instead of HTTP-based RPC, we are doing direct method invocation throughout. We also use Blazor in order to extend this concept as close to the screen as technically feasible.

Re:Why SQLite succeeded as a database (2016) by SNACKeR99 on Wednesday February 19, 2020 @08:18PM (#22371921)
Thanks for reminding me about this, just taking a quick look at it now. Quick question: do you know why it uses methods like db.InsertWithInt32Identity(product) rather than db.InsertWithIdentity<int>(product) or similar?
Re:Why SQLite succeeded as a database (2016) by to11mtm on Wednesday February 19, 2020 @09:46PM (#22372289)
> Quick question: do you know why it uses methods like db.InsertWithInt32Identity(product) rather than db.InsertWithIdentity<int>(product) or similar?

Because it's not that easy with Generics. :)

The signature of the method is as follows:

public static int InsertWithInt32Identity<T>([NotNull] this IDataContext dataContext, T obj, string tableName = null, string databaseName = null, string schemaName = null)

If we tried...

public static TIdentity InsertWithIdentity<TInsert,TIdentity>([NotNull] this IDataContext dataContext, TInsert obj, string tableName = null, string databaseName = null, string schemaName = null)

You'd actually have to write:

db.InsertWithIdentity<MyTableType,int>(myTableItem);

which is also potentially confusing if you're trying to glance at the code.

But wait, some might ask, Select has two types, how come it doesn't have this problem?

public static IEnumerable<TResult> Select<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector)

But as the signature shows, the return type is based on the expression passed as a parameter, which is why you don't have to do it there. :)

Edit: That said, there's facilitation for inserting with granular control over columns.... which is when I stopped waiting for EF to get it's act together. :)

Re:Why SQLite succeeded as a database (2016) by SNACKeR99 on Thursday February 20, 2020 @09:59AM (#22375475)
Thanks, I really appreciate the reply and hadn't thought about those side effects. I then thought "why not derive the identity type from an attribute on the identity property of the table class?", but then you have a dynamic return type, so you either return an object needing a cast, or it leads you back to the same problem you identified.
Re:Why SQLite succeeded as a database (2016) by drchickensalad on Thursday February 20, 2020 @09:20AM (#22375209)
Can't you take object instead of TInsert and call .GetType to lookup the (cached) way to serialize it? I assume this is what json.net etc do.
Re:Why SQLite succeeded as a database (2016) by felixge on Thursday February 20, 2020 @05:47AM (#22374144)
I love SQLite, but I'd be curious how you were able to saturate an NVMe drive with it. Were you doing the inserts in large batches?

Saturating an NVMe drive requires writing with very large block sizes or very high queue depths.

Re:Why SQLite succeeded as a database (2016) by bob1029 on Thursday February 20, 2020 @09:10AM (#22375141)
Inserting rows with ~500KB blob columns (JSON data) on a single connection w/ WAL enabled & pragma synchronous == NORMAL or OFF.

I will admit that it would be very difficult to saturate a disk that can write on the order of gigabytes per second if you are trying to insert rows that are only a few KB in size (at least without batching these into larger entities or requests).

Re:Why SQLite succeeded as a database (2016) by inferiorhuman on Wednesday February 19, 2020 @02:28PM (#22369086)
one connection per logical operation sucks for SQLite

How is this typically handled? Using OS file locking primitives?

Re:Why SQLite succeeded as a database (2016) by zahrc on Wednesday February 19, 2020 @03:19PM (#22369612)
Re:Why SQLite succeeded as a database (2016) by jessermeyer on Wednesday February 19, 2020 @02:28PM (#22369095)
I know SQLite's SQL query engine is implemented as a VM. Are there ways of optimizing repeated queries, similar to compiling a query to avoid the VM churn? Perhaps more importantly, have you ever been disappointed by the query engine's performance?
Re:Why SQLite succeeded as a database (2016) by nbevans on Wednesday February 19, 2020 @03:41PM (#22369825)
You can "prepare" a SQL statement and use it multiple times. I.e. you can use the same VM for a statement many times.
Re:Why SQLite succeeded as a database (2016) by zzo38computer on Thursday February 20, 2020 @01:03AM (#22373045)
You can prepare a query to use multiple times (if you are using the C interface, at least; as far as I know the command-line interface does not support this), as another comment mentions. You can also prefix a SQL statement by EXPLAIN to view the VDBE codes. But, I see that sometimes the VDBE code is not as good as it should be.
Re:Why SQLite succeeded as a database (2016) by kccqzy on Wednesday February 19, 2020 @10:20PM (#22372428)
You can put each query and the result of preparing that query into an LRU cache (or even just a static pointer in C if your application only ever deals with a single connection). Then you can reuse these without preparing them over and over.
Re:Why SQLite succeeded as a database (2016) by miohtama on Wednesday February 19, 2020 @04:50PM (#22370455)
My only grievance, and a blocker, is that SQLite does not support decimal numbers, making it less practical to work with finance related data.
Re:Why SQLite succeeded as a database (2016) by webpaymentsguy on Wednesday February 19, 2020 @04:59PM (#22370545)
You probably already heard of storing amount in cents as an integer, but it's a pattern worth mentioning if it fits your use case.
Re:Why SQLite succeeded as a database (2016) by marton78 on Wednesday February 19, 2020 @05:57PM (#22371006)
I don't know how it's done in the US, but in Europe financial calculations are done with four digits after the dot.
Re:Why SQLite succeeded as a database (2016) by catmanjan on Wednesday February 19, 2020 @07:24PM (#22371645)
So store the value as milli-cents? (haha)
Re:Why SQLite succeeded as a database (2016) by Loranubi on Wednesday February 19, 2020 @08:34PM (#22372004)
Shouldn't that be centi-cents? ^^
Re:Why SQLite succeeded as a database (2016) by inferiorhuman on Wednesday February 19, 2020 @08:44PM (#22372059)
Or in MySQL: innocents.
Re:Why SQLite succeeded as a database (2016) by Narkov on Wednesday February 19, 2020 @09:44PM (#22372282)
More likely: varchar(255)
Re:Why SQLite succeeded as a database (2016) by boshomi on Thursday February 20, 2020 @01:27AM (#22373118)
varchar(255) == varchar(2000000) in SQLite

The type system in SQLite is not as strict as it is in other RDBMS.

Re:Why SQLite succeeded as a database (2016) by miohtama on Wednesday February 19, 2020 @06:05PM (#22371074)
It is possible, but makes is somewhat impractical, because you need to convert numbers back and forth every time you touch them on an application level. Not worth the extra headache.
Re:Why SQLite succeeded as a database (2016) by luhn on Wednesday February 19, 2020 @06:50PM (#22371408)
Speaking from experience, if you exclusively deal with integers internally and then apply the appropriate formatting when outputting to the user (which you need to deal with regardless of internal representation), it makes dealing with monetary data so much easier. Integers are generally better supported, faster, and more convenient for most languages, databases, and serialization formats.
Re:Why SQLite succeeded as a database (2016) by gen220 on Wednesday February 19, 2020 @07:12PM (#22371569)
+1 adding my anecdata to this.

If you don’t need irrational numbers (few financial applications do?), the tuple of (value, scale) can take you very far.

Re:Why SQLite succeeded as a database (2016) by utxaa on Thursday February 20, 2020 @09:48AM (#22375408)
you never really deal with irrationals ... do you mean floating point?
Re:Why SQLite succeeded as a database (2016) by gen220 on Friday February 21, 2020 @10:44AM (#22383909)
Nope, specifically meant irrationals.

Floating point (up to a certain amount of absurdity) you can describe with integers (value, scale).

Real numbers you can describe with integers (numerator, denominator, scale).

Irrationals are more difficult. That's why we try not to use them :). Hopefully your company's commission tiers are not defined in terms of circles or euclidean distances.

Re:Why SQLite succeeded as a database (2016) by patrickthebold on Wednesday February 19, 2020 @08:50PM (#22372092)
How do you handle things like multiplying by some interest rate of 3.125 or (1 + 0.03125)^-354 as examples.

Sure you can round at the end but then you have to worry about compounding errors.

Re:Why SQLite succeeded as a database (2016) by anoonmoose on Wednesday February 19, 2020 @09:03PM (#22372144)
I think that's just part of the process of deciding how small an increment each integer represents (dollars, cents, centi-cents, milli-cents).
Re:Why SQLite succeeded as a database (2016) by elcritch on Thursday February 20, 2020 @03:51AM (#22373689)
Accounting rules often care more about consistency than precision per se. As long as the code follows accepted accounting rules (say bankers rounding) choosing a known precision works. Often GAAP and other standards don’t define all details for, say amortization, but if you use a scheme the code should always use that method.
Re:Why SQLite succeeded as a database (2016) by miohtama on Thursday February 20, 2020 @02:34PM (#22377840)
Numeric type, as supported by other SQL databases, does exactly this. I do not want reinvent it on the application level.

I know how to do it, it is just not practical.

Re:Why SQLite succeeded as a database (2016) by fetbaffe on Wednesday February 19, 2020 @07:15PM (#22371592)
Do you then use variable length for the precision depending on the currency?
Re:Why SQLite succeeded as a database (2016) by wruza on Wednesday February 19, 2020 @07:24PM (#22371644)
Not insisting, and could be seen as a bad practice, but I think I have experience worth sharing.

Unless you operate 2+degree currency polynomials, it may be okay to store money in minimal integer units at an application level too. It may be adjusted in only ui formatters. One should be careful with constants in code and external apis, but nothing you can’t get used to or catch with a test. We store timeouts in milliseconds, weights in grams, and so on anyway - not a new thing.

As an example, the primary database I maintain for our company is able to hold decimal .00 natively, but we use its fields as if they were multiplied by 1000, i.e. 12,345.00 is stored and operated as 12.35 (and goes as int64 1235 to ODS) (rounding 5.00 off is fine for this particular accounting model). Nobody made a three-digit mistake ever in a whole decade, because square/cubic money is not a thing naturally, and ratios & exchange rates work as usual. It is like storing cents, but the other way round.

Storing in-app amounts in floats has a downside of accumulating an error in for-looped calculations and the need for periodic rounding (although it should run on a really big dataset to collect that enough). If a language has a money type and it can be programmed accordingly, then a problem disappears. If not, then it persists either way in different forms.

Re:Why SQLite succeeded as a database (2016) by crazygringo on Wednesday February 19, 2020 @08:48PM (#22372080)
I dunno... the only alternative seems to be storing as a float everywhere, since most coding languages don't support a decimal type... and using floats for currency honestly just feels scary to me, since they're not fixed-precision.

I mean I know there are min/max ranges in the float specification that can guarantee no loss of accuracy to two decimal places... but then I need to manually make sure there's never anywhere in the code that might ever sum up transactions to beyond that, or whatever. Or people thinking it's OK to divide and then multiply, which you're hopefully less likely to do if it's an integer.

I feel much more peace of mind storing currency data as integers and doing the conversion. It feels quite natural really, since I'm already used to doing that with datetimes for different timezones.

Re:Why SQLite succeeded as a database (2016) by miohtama on Thursday February 20, 2020 @02:36PM (#22377849)
Python has Decimal, JavaScript has BigNum and so on. I disagree with you - most languages support arbitrary precision numbers. Floats are not needed or wanted.

You so not want to invent your own arbitrary precision numbers

https://floating-point-gui.de/formats/integer/

Re:Why SQLite succeeded as a database (2016) by fetbaffe on Wednesday February 19, 2020 @07:19PM (#22371612)
What is the drawback of just using a string as storage? Together with something like bcmath for calculations.

Strings does not overflow & are easy to transfer.

Re:Why SQLite succeeded as a database (2016) by manigandham on Wednesday February 19, 2020 @10:07PM (#22372364)
Applications can handle integers just fine, even more of a reason to use them. 64-bit integers will work everywhere seamlessly and you only need to convert once, when showing them in the UI and/or collecting user input.
Re:Why SQLite succeeded as a database (2016) by manigandham on Wednesday February 19, 2020 @10:08PM (#22372373)
Use a 64-bit integer and store the value as microdollars (or whatever main currency you're using). Simple, fast, correct, and compatible everywhere.
Re:Why SQLite succeeded as a database (2016) by Scarbutt on Thursday February 20, 2020 @01:41AM (#22373163)
Re:Why SQLite succeeded as a database (2016) by tommica on Thursday February 20, 2020 @02:11AM (#22373291)
Just to give context, the link points out possible drawbacks with the approach mentioned above
Re:Why SQLite succeeded as a database (2016) by patrec on Friday February 21, 2020 @03:23AM (#22381694)
> Integers have complete precision, but very limited range

You can store up to 900 trillion dollars with 0.01 cent resolution in an int64. I doubt many applications need more range than that.

> when [integers] overflow, they usually “wrap around” silently

If you want to write an application handling money, you really want to use a Money type of some description, regardless of whether the underlying storage format is an integer. So it's very easy to avoid silent overflows, since basically all languages that are prone to them also offer primitives that check perform addition, subtraction and multiplication with checks for over/under flow.

> The implicit decimal point is hard to change and extremely inflexible

If you have a Money type, it's not hard to change. The pain point would normally be serialization, but that's not necessarily different from using decimal floating point internally, since very few APIs, serialization protocols or even databases have native support for fp decimals either.

> The number of subunits in currencies change with time in the world.

I suspect Goverments are equally or more likely to drop trailing zeros (e.g. Iraq did not so long ago), which you also need to deal with anyway and which does not get easier by using a floating point format.

Re:Why SQLite succeeded as a database (2016) by BlueTemplar on Wednesday February 19, 2020 @06:14PM (#22371154)
Wait, there are finance applications that don't forbid floating point numbers ??
Re:Why SQLite succeeded as a database (2016) by zimbu668 on Wednesday February 19, 2020 @06:34PM (#22371301)
Re:Why SQLite succeeded as a database (2016) by fowl2 on Wednesday February 19, 2020 @06:58PM (#22371480)
I'd like you to meet my friend "Excel"...
Re:Why SQLite succeeded as a database (2016) by BlueTemplar on Saturday February 22, 2020 @08:28AM (#22390870)
I mean for professional applications, not amateur stuff.
Re:Why SQLite succeeded as a database (2016) by Dylan16807 on Wednesday February 26, 2020 @03:17AM (#22421325)
Excel is used for very very expensive professional tasks.
Re:Why SQLite succeeded as a database (2016) by Zarel on Wednesday February 19, 2020 @08:21PM (#22371947)
They're talking about decimal numbers as a different thing from floating point numbers:

https://en.wikipedia.org/wiki/Decimal#Decimal_computation

Re:Why SQLite succeeded as a database (2016) by bob1029 on Wednesday February 19, 2020 @08:35PM (#22372013)
You know its strange - We work with an incredible number of decimal facts (financial data), but we find that this has zero impact on our SQLite usage because we have policy where extremely complex business entities that are prone to rapid change are serialized to JSON and stored as BLOB columns. Within this JSON serialized data is where virtually all of our decimal values reside. Obviously, its not a solution for any arbitrary case, but you can usually find workarounds in interesting places further up the stack. We use only 3 data types in SQLite - BINARY, TEXT and INTEGER.
Re:Why SQLite succeeded as a database (2016) by zzo38computer on Thursday February 20, 2020 @01:52AM (#22373213)
There is no BINARY type in SQLite. (However, the declared type mostly does not restrict the data that column may store. All columns can store blobs and nulls (unless NOT NULL is specified). Columns declared CHAR, VARCHAR, CLOB, CHARACTER, or TEXT can store only text, blob, and null; trying to store a number will convert it to text. Columns declared REAL, FLOAT, or DOUBLE cannot store integers; they are converted into floating numbers; if you try to store text representing a number, it is converted to that number. Columns declared INT, INTEGER, NUMERIC, or an unrecognized type (such as BINARY) can store any value, but text representing a number is converted to a number, and floating numbers which can be losslessly represented as integers are converted to integers. Columns declared BLOB or with no type specified can store any value.)
Re:Why SQLite succeeded as a database (2016) by lukevp on Wednesday February 19, 2020 @11:32PM (#22372688)
How do you do reporting on these blobs?
Re:Why SQLite succeeded as a database (2016) by massysett on Wednesday February 19, 2020 @08:13PM (#22371893)
In addition to the other workarounds suggested, you can store the numbers in two columns - one for the coefficient and one for the power of ten, negated. For instance 2.50 becomes 250 and 2, meaning 250 x 10 ^ -2. You can then do math at the application level, or even in SQLite with user-defined functions or even with recursive CTEs if you’re a bit of a masochist.
Re:Why SQLite succeeded as a database (2016) by porker on Thursday February 20, 2020 @03:47AM (#22373666)
There is a SQLite decimal extension, unfortunately still under development and not finished: https://chiselapp.com/user/lifepillar/repository/sqlite3deci...
Re:Why SQLite succeeded as a database (2016) by anitil on Thursday February 20, 2020 @06:40PM (#22379666)
Interesting extension. I'm not from the finance field so I don't know the kind of regulations/standards are used. Do you happen to know?
Re:Why SQLite succeeded as a database (2016) by mrighele on Thursday February 20, 2020 @01:23AM (#22373107)
> The trick is to use a single connection and let SQLite handle the serialization for you, rather than try to manage multiple connections to the same file in code (i.e. one connection per logical operation sucks for SQLite).

It seems to me that in that case you cannot use transactions though, or am I wrong ?

Re:Why SQLite succeeded as a database (2016) by easytiger on Thursday February 20, 2020 @03:25AM (#22373580)
You can use transactions. They determine batch persistence of the data rather than persisting every insert.

You can just batch them up by

    mod N inserts or Z milliseconds
if you have enough data If you don't particularly care you can disable syncing too.
Re:Why SQLite succeeded as a database (2016) by NicoJuicy on Thursday February 20, 2020 @06:46AM (#22374368)
For programming, the use-case for EF or expression-tree queries is the specification pattern.

Although you are correct that it doesn't handle complex queries very fast ( the ORM), there is definitely a valid motivation to use/enforce it.

Complex queries are mostly handled through something like elastic search or search engine ( azure), the goal is to keep queries simple and if the code is loosely coupled, it's easier to do this.

Re:Why SQLite succeeded as a database (2016) by OrgNet on Wednesday February 19, 2020 @09:43PM (#22372276)
Doesnt sqlite fail fast when many users commit at once?
Re:Why SQLite succeeded as a database (2016) by samatman on Wednesday February 19, 2020 @11:57PM (#22372787)
There's a level of write-heaviness after which SQLite, even in WAL mode, is the wrong choice.

But one can get pretty far with this design. Thousands of writes per second from a few dozen writers, no problem. Millions and hundreds, I'd use something else for that.

Re:Why SQLite succeeded as a database (2016) by Scarbutt on Thursday February 20, 2020 @01:05AM (#22373050)
Or if you have 10,000 writers each taking 10ms, that's 100 WPS, not bad for most apps.