News for hackers. Stuff that matters.
Re:Cross-Database Queries in SQLite by tlb on Sunday February 21, 2021 @06:19PM (#26218370)
I've done the flatfile thing several times on various projects, and I'm starting to appreciate the wisdom of letting sqlite handle it. Things it can handle correctly include:

- crashes/power failures

- multiple processes opening the same file

- transactional updates: it rolls back if you throw an exception in the middle of writing the update. This seems like a common failure mode while under development

- scaling to huge size: many gigabytes are no problem. These get slow with a flatfile

- manual surgery on data: it comes with handy command line tools for manipulating its databases

- upgrading format: you can check a version number when opening the file and do "alter table add column" for any new features.

Re:Cross-Database Queries in SQLite by mlthoughts2018 on Sunday February 21, 2021 @07:00PM (#26218671)
I feel like if I am worried about those issues, when would I ever use sqlite instead of Postgres?

Sqlite seems like it is only appropriate for the knife’s edge boundary between small data, low reliability, in-memory situations (better served by server applications using tools like pandas or R) and bigger data, transactional structure, reliability constraints (better served by Postgres).

I just can’t understand what use cases live in between them and are better served by sqlite.

Re:Cross-Database Queries in SQLite by nodamage on Sunday February 21, 2021 @08:11PM (#26219375)
There are literally billions of smartphones in the world that fall in between those exact constraints...

It's honestly bizarre to me to see someone claim that Sqlite has few use cases when there are likely hundreds of Sqlite files sitting in the phone in your pocket.

Re:Cross-Database Queries in SQLite by milch on Sunday February 21, 2021 @10:43PM (#26220632)
There’s probably files on their computer as well that use SQLite. Lightroom libraries are SQLite databases for example, which is a pretty leaky abstraction in their case
Re:Cross-Database Queries in SQLite by zetalemur on Sunday February 21, 2021 @07:21PM (#26218848)
> I feel like if I am worried about those issues, when would I ever use sqlite instead of Postgres?

Sometimes you do not want to run an additional process/daemon like postgres. Your state is in essence now a file on some file system that you can atomically (full ACID) update using multi processing without the need for more complex machinery - you can get very far with this architecture.

Re:Cross-Database Queries in SQLite by ehvatum on Sunday February 21, 2021 @07:44PM (#26219068)
For example, SQLite is excellent for making an email client. Even on old embedded Arm devices with 64MiB memory, it’s fast enough to handle a gigabyte of messages and an address book with thousands of entries, provided the SQLite DB is located on a good CF or SD card. SQLite is really quite remarkable for the number of occasions where it has been immensely valuable to me and countless others, on such a variety of platforms and in such a variety of circumstances.
Re:Cross-Database Queries in SQLite by CraigJPerry on Sunday February 21, 2021 @07:37PM (#26218987)
For interactive use, sqlite queries are snappier than pandas at the ~4gb dataset size. I’ve switched over for some logfile analysis tasks and both memory usage and speed are a bit better.

They’re not massive differences but i definitely appreciate the snappiness. Interactive work is just nicer that way.

I could do postgres - the docker version is pretty handy i find but it’s just more faffing about (-v /path/to/wherever:/var/postgres password, cleanup when you’re done etc.)

Re:Cross-Database Queries in SQLite by chrisweekly on Monday February 22, 2021 @07:35AM (#26223761)
For logfile analysis, take a look at https://lnav.org -- it has SQLite embedded, along with a bunch of helpful utils for ETL on a small scale.
Re:Cross-Database Queries in SQLite by CraigJPerry on Monday February 22, 2021 @10:54AM (#26225906)
I'll need to give that a whirl, one feature i like the look of from glancing the docs - https://docs.lnav.org/en/latest/hotkeys.html#chronological-n...

Sure beats regexing my way to the next minute marker or whatever.

Re:Cross-Database Queries in SQLite by iagovar on Monday February 22, 2021 @03:15AM (#26222056)
If you're using pandas, try duck db
Re:Cross-Database Queries in SQLite by quietbritishjim on Sunday February 21, 2021 @07:40PM (#26219030)
Perhaps you could answer the opposite question:

Why would I use flatfile (aside from the fact I've never heard of it) over SQLite? So far you've just said SQLite has some features you can't imagine I'd ever need, but even if that were true then it wouldn't be a problem in itself. What are things that are actually bad about SQLite compared to the alternative you're suggesting?

Re:Cross-Database Queries in SQLite by techbio on Monday February 22, 2021 @02:36AM (#26221816)
Possibly adding the complexity of SQL, or an ORM, in their use case is a layer of complexity beyond reading and writing serialized data structures to text.

Not sure why the sibling posters determined s/flatfile/flatfiles/ the most interesting part of your question.

Re:Cross-Database Queries in SQLite by dmd on Sunday February 21, 2021 @08:39PM (#26219666)
You've never heard of using a file to store data in?
Re:Cross-Database Queries in SQLite by quietbritishjim on Sunday February 21, 2021 @09:32PM (#26220113)
The question was what is the benefit of flatfile over SQLite. SQLite stores the database in a single file, so "it uses a file" is not an answer to that.
Re:Cross-Database Queries in SQLite by nl on Monday February 22, 2021 @12:44AM (#26221271)
Flatfile means a plain text file, generally one you can process on a row-by-row basis. It sounds like you think there is some software called "flatfile", but it is a reasonably common term.

There are advantages over SQLite, eg: the ability to use unix command line tools against the file directly.

In my view SQLite has more advantages though.

Re:Cross-Database Queries in SQLite by HelloNurse on Monday February 22, 2021 @05:41AM (#26222966)
Altering data with text editors is more or less the opposite of the integrity afforded by a database.

Of course principled command-line tools for text (e.g. awk) and the possibility of running arbitrary SQL queries on a database blur the line, but the distinction between files that are read or written once as a step in a transformation pipeline or as something to load or save and databases that represent a persistent state, with transactions, remains sharp.

Re:Cross-Database Queries in SQLite by dmd on Sunday February 21, 2021 @09:41PM (#26220176)
My comment was that you seem to be under the impression that there is a piece of software or file format named 'flatfile'.
Re:Cross-Database Queries in SQLite by quietbritishjim on Monday February 22, 2021 @08:48AM (#26224434)
Oh. It would've been easier if you'd just said that in your first comment.

Looking back, you seem to be right. I thought mlthoughts2018 was referring to a specific file format, or at least a specific library because (1) They made up that weird terminology "flatfile" which looks like product name instead of just saying "plain text file" ... I wonder why they did that? (2) They made claims about transactional integrity with a WAL-like log. Now I realise they were suggesting you homebrew that anew for each fresh project that needs to store data! The idea that this would be easier than just using SQLite's existing mechanisms is so bizarre it didn't even enter my head they could've meant that.

Re:Cross-Database Queries in SQLite by rodgerd on Monday February 22, 2021 @12:17AM (#26221127)
Why on earth do I want the overhead and attack surface of a full, multi-user, networkable database with user-defined languages, extensions, and all of the other amazing things that PG can do, when all I need is a reliable, single-user structured data store?