14 ms·
DuckDB – An embeddable SQL database like SQLite, but supports Postgres features
- viraptor 6y agoI was hoping from the title that it aims for postgres SQL compatibility, but I can't find it explicitly mentioned in the docs. This really makes me think I really want something like sqlite://memory which completely disregards speed or even persistence. Instead you could say for example "open an in-memory database that behaves like postgres 9" and run your tests against it. With typical fixtures of 10 or so rows, you wouldn't even need a query plans - just naive filte+copy over whole tables for most operations. Currently I'm using https://pypi.org/project/testing.postgresql/ https://pypi.org/project/testing.postgresql/ which spawns a temporary server per each test suite, which has quite a lot of overhead.
- chrisdalke 6y agoI would also love this, in the past I’ve used the H2 in-memory database for tests with Spring boot applications. The Hibernate ORM handles configuring the H2 schema but they’re not fully compatible, so it means I have to be careful to not rely on Postgres-specific features. I generally am not testing database logic, just need a working persistence layer to get the tests running, but an in-memory Postgres implementation would be amazing.
- viraptor 6y agoAlthough it's something I'd love to write, supporting it over a long time as pure FOSS would probably be a sad experience. I wonder what model could be used here. Maybe something like patreon or "sponsor a feature" with an open-source project? FOSS core + proprietary Java / .NET bindings because corps can pay?
- chrisdalke 6y agoYeah, for sure this is the type of niche, high-effort work that would be used extensively by the closed-source world and yet struggle to find adequate support.
- vips7L 6y agoIIRC h2 supports a postgres compatibility mode. Though I'm not sure how feature complete it is. http://h2database.com/html/features.html http://h2database.com/html/features.html
- c17r 6y agoMan, I’ve wanted the “compatible SQL engine with only RAM storage” for testing for YEARS. Closest I got was some shenanigans with MSSQL’s LocalDB.
- mStreamTeam 6y agoI use docker to spin up new postgresql DBs on the fly
- toyg 6y agoI do that too but it’s a noticeable overhead, I guess it wouldn’t be great for mass-testing scenarios.
- GordonS 6y agoSame here, and I run the same set of migrations that run in production. To he clear, this is only done once per test session, not for individual tests, and the tests are written in such a way that they don't interfere with each other. The overhead is actually pretty small, less than 10s. I'd saw too much for unit tests, but we'll within the tolerable range for integration/functional tests. Compared with the time I'd spend hacking together some brittle and unrealistic in-memory alternative, I much prefer to use a real database.
- striking 6y agoRAM FS + fsync off?
- viraptor 6y agoThose solutions still have a high overhead. There's acid compliance, serialisation in memory, maintaining indices, and many other layers. Compare it to an ideal testing solution with no initialisation cost and insert being literally: parse the query, add a new entry to a list, done.
- RantyDave 6y ago
- giancarlostoro 6y ago> SQL Parser: We use the PostgreSQL parser that was repackaged as a stand-alone library. The translation to our own parse tree is inspired by Peloton. Right at the bottom of this page: https://duckdb.org/docs/why_duckdb.html https://duckdb.org/docs/why_duckdb.html
- viraptor 6y agoThat's awesome news, thanks for that!
- giancarlostoro 6y agoNo problem I was curious as well and hunting it down, this project does seem interesting, I'm a huge fan of database systems like SQLite and H2. There's something wonderful about being able to copy a simple file and share it with other developers. This one seems rather interesting as well.
- dd36 6y agoThat’s what made Excel so popular.
- jrockway 6y agoI would just create a per-test-file database (and delete it the next time the test runs). The overhead is very small (compared to booting Postgres) and it works exactly like production because it is exactly production. In general, I am not comfortable using an "almost equivalent" database for tests. Every database engine has its quirks, and if you don't know what they are, your program that passes its tests only "almost" works in production, which is annoying.
- oauea 6y agoAnd if you need to run expensive migrations, use a template database. https://www.postgresql.org/docs/current/manage-ag-templatedbs.html https://www.postgresql.org/docs/current/manage-ag-templatedb...
- majodev 6y agoWhile PostgreSQL templates allow to scaffold new databases (one per test-spec) quite fast, it's even faster to have a warmed up pool of databases ready: https://github.com/allaboutapps/integresql#background https://github.com/allaboutapps/integresql#background Disclaimer: author.
- oauea 6y agoOh that looks great, and very close to what I had in mind for the next upgrade of our in-house testing framework. Definitely going to give that a try soon. Thanks for posting it!
- mytherin 6y agoOne of the authors of DuckDB here: we use the PostgreSQL parser, and try to be generally compatible with the syntax used by SQLite, Postgres and MySQL. In some cases those are unfortunately mutually exclusive (e.g. null ordering - we have a PRAGMA to change this system-wide). Making the SQL dialect “as compatible as possible” with these systems is very much one of our goals, and if you find any incompatibilities feel free to open an issue :)
- mst 6y agoI'd note that when moving from pg to $other the thing that really trips me up isn't the syntax changes, it's the lack of ARRAY and ROWTYPE. I'm not sure whether those are in scope for you but it'd be nice if the docs said "to be implemented" or "out of scope" somewhere ... and my apologies in advance if they do and I somehow missed it.
- mytherin 6y agoWe already have support for LIST and STRUCT (which I think are equivalent to ARRAY and ROW, respectively). There is still some functionality missing there (notably storage, and several functions) - but the base functionality is there and the remainder definitely will be added.
- mst 6y agoCould only find a pull request on struct, and nothing at all on 'list' because I just got a billion 'select list' articles. Also nothing in the docs. Struct looks 10x uglier but perfectly easy to generate, mind, but the whole thing is non-trivial to find :/
- dkarlovi 6y agoYou shouldn't rely on any "just like X" systems for tests, you should use X exactly, including correct config and version as production. What you want is having a Postgres server, but optimized for tests. What I've done is 1. One instance per pipeline 2. Parallelize by having separate databases per process 3. Build schema once 4. Before each test, purge the database (or run tests in transactions so you can just rollback in the end) 5. Run in Docker, use tmpfs volumes for writes (no disk writes) It runs fairly quickly.
- torrance 6y agoStrict typing has been the one big feature missing from SQLite, that this presumably brings.
- gralx 6y agoForeign keys enabled by default or by configuration setting would be another big feature missing from SQLite3, but I couldn't find any mention of foreign keys in DuckDB's documentation.
- Master_Odin 6y agoIt doesn't look like it provides FK looking at the create table syntax. Just PKs, unique, and check on an expression similar to sqlite.
- cryptonector 6y agoWhat? SQLite3 absolutely has FKs.
- gralx 6y agoYou just have to write PRAGMA foreign_keys = on; each and every single time you want to do an operation that requires an FK constraint, like `INSERT`.
- mceachen 6y agos/each and every single time/once when you instatiate a new database connection/ ftfy. You really shouldn't be needing to create new connections often. Really only once for any given process. There are some 20 PRAGMAs that PhotoStructure sets for library databases, but it's only at process startup, and it takes a couple millis to run them all. It's wonderful to be able to configure stuff so easily. I also think the design decision for backward comparability (which meant this default is false) is absolutely defensible.
- deleted 6y ago[deleted]
- awb 6y agoCool project. Really appreciate the "When to use DuckDB" and "When to not use DuckDB" sections. Anyone using this in production? Also, any benchmarks vs. other DBs?
- legg0myegg0 6y agoI work at a Fortune 100 company and we have this in production for our self-service analytics platform as a part of our data transformation web service. Each web request can do multiple pandas transformations, or spin up it's own DuckDB or SQLite db and execute arbitrary SQL transformations. It fits our use case like a glove and is super fast to/from Pandas.
- xiaodai 6y agoSay I want to fix logistic Regression. Can I do that in database? Or have to extract it out as a dataframe? Cna I stream the data?
- winrid 6y agoIf you want to do linear regression aggregations with any DB, one thing you can do is store the coifficents and then aggregate them on request. You sacrafice some accuracy for speed.
- xiaodai 6y agoModel fitting. How to do?
- prionassembly 6y agoStochastic gradient descent.
- adrianmonk 6y agoFirst of all, really neat project. There's an issue with the Installation section of the web page, though. Running Chrome on Linux, it says "System detected: Linux", which is right. But under "CLI", it offers me a download of duckdb_cli-osx-amd64.zip. Just in case it was just the zip file name that's wrong, I downloaded it, but the duckdb binary inside is a "Mach-O 64-bit x86_64 executable" according to the file command. The correct file is available if I click on Other Installations (https://duckdb.org/docs/installation/ https://duckdb.org/docs/installation/). Also, if I try it on running Firefox on Linux, it says "System detected: UNIX" and gives me the OS X download.
- mytherin 6y agoThanks for reporting that! We will have a look at fixing it :)
- alexchamberlain 6y agoFWIW I got the same issue on Android, though offering me the "correct" link wouldn't do me much good either :)
- simonw 6y agoI spent a while looking at this today. It's really interesting. It's not based on SQLite at all (except for borrowing the SQLite shell implementation) but it looks very much like SQLite, in particular: - It's designed to work as an embedded library, eliminating the network overhead you usually get when talking to a database - Each database is a single file on disk - It ships as an "amalgamation" build - a single giant C++ file (SQLite is a single giant C file) Impressively, if you run "pip install duckdb" it Just Works - you can then "import duckdb" and start using it, with an interface that looks very similar to the sqlite3 module that ships with Python. The key reason this exists is that it's a column store, with vectorized operations across columns - making it ideal for analytical workloads. This blog entry has some benchmarks that illustrate how well it works in that regard: https://uwekorn.com/2019/10/19/taking-duckdb-for-a-spin.html https://uwekorn.com/2019/10/19/taking-duckdb-for-a-spin.html It's also backed up by some strong computer science. It's by the academic researchers behind MonetDB and includes implementations of a bunch of interesting papers: https://duckdb.org/docs/why_duckdb#standing-on-the-shoulders-of-giants https://duckdb.org/docs/why_duckdb#standing-on-the-shoulders... It's a really interesting piece of software, and unlike many other "new databases" it feels like it fills a very genuine gap in my toolbox.
- haggy 6y agoI really appreciate the breakdown here but this comment smells like a giant plant for DuckDB.
- gregsadetsky 6y agoI don’t think that it’s reasonable to assume that Simon would risk his reputation by coming here to astroturf.
- Smerity 6y agoA giant plant as in someone from their team planning this out and then planting this as a comment..? simonw wrote Datasette[1] which makes extensive use of SQLite and acts as a viewer, allowing you to create interactive websites and APIs from arbitrary databases. He'd be a very long term plant and it instead seems far more likely he's interested in the possibilities of DuckDB compatibility within the context of Datasette and other similar projects. [1]: https://github.com/simonw/datasette https://github.com/simonw/datasette
- threcius 6y agoGood name.
- ksec 6y agoI really wish ALL software project / framework / libary could follow the lead here. Instead of your marketing page telling me how world changing awesome tech you have, which really is a consumer marketing strategy. Just do it like DuckDB, When to use DuckDB ; When to not use DuckDB
- LockAndLol 6y agoI couldn't put my finger on why I felt like I had just read something useful, but that's it: clear, concise and straight-forward information to help you evaluate use. Only thing wrong I saw was the detection of the platform. It detected my linux box as "Unix" and proposed I download OSX libs.
- fsloth 6y agoWhat an excellent point! I suppose the consumer marketing strategy comes from pure imitation - people look around them how "professional" products discuss themselves - with the aim of selling a product and service - and simply copy that. Algorithms textbooks don't create marketing blurbs for linked lists...
- FridgeSeal 6y agoWe should make a list of technology that does this, because I know Clickhouse also has a reasonably detailed page on when to use it and when to not use it and why. Postgres also has a very nice “do and donts” wiki page.
- stjo 6y agoPostgres “do and donts”: https://wiki.postgresql.org/wiki/Don%27t_Do_This https://wiki.postgresql.org/wiki/Don%27t_Do_This
- ComodoHacker 6y agoLooks like DuckDB doesn't seek investments. So they can afford to be defeloper-first. Not everyone can, though.
- maigret 6y ago
- stormdennis 6y agoThis sounds great. I wonder if there are plans for an ODBC driver at any point?
- mraza007 6y agoJust curious about these Do you think embeddable databases are common in car navigation systems
- davidgaleano 6y agoCan multiple separate clients access the same single-file database at the same time?
- hfmuehleisen 6y agoOne of the DuckDB authors here. The answer is yes, but only in read-only mode at the same time.
- davidgaleano 6y agoWhat about one single client writing and multiple clients in read-only mode? Any problems with storing the file on network storage? Basically, how far can you push it before it is better to just use PostgreSQL?
- mastazi 6y agoI think the title chosen by the poster misses the mark a bit, the main point seems to be that it’s an OLAP DB optimised for analytics.
- zmmmmm 6y agoAmazing work! It was asking a lot, but still :-( that JSONB and range datatypes are missing.
- Piisamirotta 6y agoThis is slightly offtopic but do you guys have any good guides/best conventions how to save timeseries data to sqlite/similar? I'm no DB expert so struggling with this. I'm having a dynamic number of measurements that usually have the same timestamp. So one table for timestamp_id, signal_id and value?
- jsumrall 6y agoVery cool project! Seems basically to be a column store and stores everything in a single file. That reminds me of LMBD, which is similar in some ways, except bring a key/value store. Very highly recommend checking it out too to see what embeddable DB makes sense for your project. http://www.lmdb.tech/doc/ http://www.lmdb.tech/doc/
- pknerd 6y agoAny GUI Client to explore data?
- infinite8s 6y agoWeb or desktop?
- sovasovad11 6y agoNeat project..does it support fulltext queries?
- apexol 6y agoLooks interesting! Are there any .NET Core specific drivers available?
- ryndbfsrw 6y agoThe performance of DuckDB's predecessor, MonetDBLite, was/is stellar. DuckDB, when I tried in 6 months ago, was a bit behind in terms of csv parsing or aggregation by groups and didn't seem much faster than regular sqlite so I didn't really jump at it. Does anyone here know if the performance improved since then and how it compares to MonetDBLite?
- mytherin 6y agoWe are currently actively working on performance optimization, and have recently finished implementing parallelization. Expect more performance improvements soon :)
- xgenecloud 6y agoKudos, much needed. Neat documentation. Would love to try with JS APIs.
- Sm0keDev 6y agoAmazing ...
- unnameduser1 6y agoCan someone recommend whats the best way to connect to a memory DuckDB instance from php(php_fpm) and get return in usable format? E.g. would be used for offline statistical analysis Alterntively, any way to export cli sql results as csv?
- sradman 6y ago3-month old HN thread [1] with good information from the authors and others. “An embeddable column store for data science” (Pandas and dbplyer) would have been a good description at that time but the addition of JDBC/Java support expands the use cases. [1] https://news.ycombinator.com/item?id=23287278 https://news.ycombinator.com/item?id=23287278
- secondcoming 6y agoIs this backward compatible with SQLite?
- jononor 6y agoThe on-disk format is different it seems. But there is an implementation of the SQLite C API for interacting with the database. So it depends on which level / what purpose you want compatibility.
- RileyJames 6y agoThis sounds like a solution I’d use. Embedded. Simplifies simple sites.
- 3np 6y agoPlease think twice before choosing an embeddable database for hostable software. I see so many open-source projects that get hampered own the line because they chose sqlite and there's now a SPoF that would require a significant rewrite to eliminate - especially as sqlite depending on configuration either corrupts or becomes extremely slow when stored on distributed/network file systems. I assume this goes for duckdb as well. Embeddable databases absolutely have legit use-cases, but I see them being used for projects where it'd have saved so much trouble to use a proper ORM (perhaps with sqlite support!) from the beginning.
- brunoluiz 6y agoNot sure where an ORM would help in this case. If anything, it might get in the way sometimes (in terms of performance), as some queries might not be well optimised. But yeah, people shouldn't just "follow the hype". They should always ask why would use this and not that.
- 737maxtw 6y agoI think ORM might have been brought up because in many embedded DBs there is some level of language native bindings that eliminate the need for an ORM. A couple of examples that come to mind would be mnesia (KV store rather than SQL but still an example) or some of the SQLite providers for c# which give you their own mini orm (that you will have to refactor if you change out dbs instead of using sqlite with an orm from the get go) My preference for ORMs is still on the 'give me a SQL DSL and map my objects' side. Let me use SQL as SQL, give me convenience in interfacing with the DB. Complex features like object tracking tend to be nice up front but require extra diligence down the line to avoid pitfalls, and tend to be risky from a standpoint of composability. Sorry. Almost went on an ORM rant there.
- GordonS 6y agoI guess the thought behind using an ORM here was as an abstraction over the database/storage layer, so theoretically you could change switch out the database easily. In practice though, real projects often have to sidestep the ORM and handwrite SQL, sometimes using database-specific features.
- jononor 6y agoWhat would be the recommended way to migrate data from SQLite and DuckDB? Should I dump SQL from SQLite and load in DuckDB? Or use Parquet, or CSV export/import? I think those interested in the tagline "like SQLite but more features" might be interested in a quick howto/guide like that.
- agustif 6y agoI was discussing with a coworker what would be the best option, embbbedabble or service for a database runnning for a Windows GUI app. My bet was on embeddable, so SQLite, is that the right choice? It seeems a nightmarish scenario to have 500 postgres instances running on client machines and being accessible from the internet albeit with security enabled and such... am i right?
- alecco 6y agoCountless mobile apps use SQLite.
- agustif 6y agoIn this case though I'm talking of a COBOL backend very old windows app. We want to move data from COBOL files to a database, we're making our own migration tools/scripts in python (In order to mainly rename weird name table/column names to sanish ones), and we can target any SQL flavour/database we want to insert that data at.. the question is what's the better call here... SQLite seems pretty good enough, at least until we can move our whole app to a more web-friendly environment at which point something like postgres might make more sense? but that could take a couple years... (we're a small team/company in a very specific niche/locale)
- 737maxtw 6y agoSQLite works well for app files. Bentley uses it for all sorts of stuff and I had way fewer corrupt files in their format than Autodesks. :) Do note that sqlite itself doesn't have the kindest handling of date/times, you are at the mercy of your data provider (unless you are going native) Especially when timezones are involved. If it's running on windows machines you could consider Sql Server LocalDB (runs in user mode, i believe you are allowed to distribute as such in an app). But it doesn't sound like that would make sense from what I've read for your case and tech stack. Sqlite is a good start because even if you are wrong, it should be pretty dang easy to migrate to whatever is right. :)
- 6y ago
- chrismorgan 6y agoWhat is it that makes a database an OLAP database rather than a generic relational database? Expressed otherwise: why would I choose DuckDB over SQLite, or SQLite over DuckDB?
- FridgeSeal 6y agoOLAP databases can/are still Relational databases. The difference is that they’re optimised for different workloads. SQLite/MySQL/Postgres/MSSQL etc are all OLTP databases whose primary operation is based around operations on single (or few) rows. OLAP databases like ClickHouse/DuckDB, Monet, Redshift, etc are optimised for operating on columns and performing operations like bulk aggregations, group-bys, pivots, etc on a large subsets or whole tables. If I was recording user purchases/transactions: SQLite. If I was aggregating and analysing a batch of data on a machine: DuckDB. I read an interesting engineering blog from Spotify(?) where in their data pipeline instead of passing around CSV’s or rows of JSON, passed around SQLite databases: DuckDB would probably be a good fit there.
- chrismorgan 6y agoI gather that there may be some differences in functionality offered, but that it’s probably not much. So I presume performance is the biggest area of difference. In that regard: how big are the differences in performance for each category’s representative workloads?
- greggyb 6y agoI routinely see order of magnitude or greater improvements moving analytical workloads to compressed, columnstore engines vs rowstore engines. The shortest useful description I can give of what constitutes an analytical workloads is that it is table-scan-heavy, and often concerned with a small subset of columns in a table.
- legg0myegg0 6y agoBefore the latest optimization, and only using 1 core, vs. SQLite we were seeing 133x performance on a basic group by or join, and about 4x for a pretty complex query. It was roughly even to Pandas in performance, but it can scale to larger than memory data and now it can use multiple cores! As an example, I could build views from 2 Pandas DataFrames with 2 columns and 1 million rows each, join them, and return the 1 million row dataset back to Pandas in 2 seconds vs. 40 seconds with SQLite/SQLAlchemy... Pretty sweet. DuckDB is going to be even faster now I bet!
- KingOfCoders 6y agoSorry for my perhaps stupid question, has anyone tried this with ESP32/Arduino? I would need an anlytical DB for an hiking application (Temperatur/Pressure data etc.)
- Avamander 6y agoOoh, this sounds like a fun use-case but a power loss sounds super painful.
- KingOfCoders 6y agoWould also store on MicroSD.
- jimsmart 6y agoThat’s part of the problem. Power loss during SD card write will, more likely than not, cause corruption - FAT file systems do not have journaling.
- KingOfCoders 6y agoWell yes. But then it's just hiking not emergency services, SD cards also do break, so I would need dual slot etc.
- akkishore 6y agoCan we create a view over multiple parquet files?
- mytherin 6y agoYes, totally possible. You can use UNION ALL to merge them together. We are also working on globbing support for the Parquet reader that should be released next week [1]. [1] https://github.com/cwida/duckdb/issues/773 https://github.com/cwida/duckdb/issues/773
- sterlinm 6y agoThis talk they did with a database research group at CMU may be of interest as well. https://youtu.be/PFUZlNQIndo https://youtu.be/PFUZlNQIndo
- cmrdporcupine 6y agoI love/hate it when I see pieces of software come out that would solve problems I had 10 or 15 years ago and had imperfect solutions for. This would have been great for a software project for call centre analytics I was employed to work on back in the mid-2000s. I believe I used HSQL (embedded Java DB) but it was really not the right tool. At the time I looked at MonetDB but its architecture wasn't right for what I was doing. This would have fit the niche perfectly. This is really neat. Wish I had a problem I could use it for now.
- tracker1 6y agoI used embedded firebird for a couple projects in the early/mid 2000's myself. Wish it were a bit more popular.
- ulanmaasan 6y agoSo I tried a simple query in the live demo and it seems that the WHERE clause isn't filtering anything. Am I missing something? SELECT * FROM part WHERE p_size = 7;
- mytherin 6y agoLooks like a bug, likely related to an optimizer since adding count(*) does produce the correct result. I will have a better look after the weekend. The demo runs a relatively old version so it’s possible it has already been fixed in the meantime. Thanks for the report!
- mytherin 6y agoShould be fixed now. This was an old bug related to filter pushdown into scans. The demo now runs the latest version of the system. Thanks again for the report!
- kfk 6y agoHow does duckdb compare to aws athena or spectrum? Both services offer sql directly on parquet files. I guess you would say duckdb is not distributed but if you create one on time when the user needs to run the sql on the parquet you’d be in a similar use case?
- microtherion 6y agoA suggestion for the web site: It would be good to mention the license more prominently. I had to click through to Github to find out what it was, and I believe this information would matter to more people than just me.
- CRConrad 6y agoDunno if this was put up in reaction to your comment, or you missed it, but looking at their front page right now it says “Permissive MIT License”.
- microtherion 6y agoCorrection: As CRConrad, whose comment was inexplicably downvoted, pointed out, the MIT License IS mentioned on the front page (And the Wayback Machine proves it was mentioned before the HN post).
- stormdennis 6y agoSo could the DuckDB, Postgresql combination function in a manner analogous to Firebird which has both embedded and server modes. I'd find that really exciting
- aabbcc1241 6y agoSimple, embedded database deserve more attention, especially those with native language support, e.g. map,filter,reduce methods on wrapped data that behave similar to javascript array; and support to nested data structure (like auto join and normalize). (I made one using Proxy API, called ref-db. The cons is it require manual indexing to speed up lookup by non-primary key)
- dcl 6y agoI will definitely look at using this for some personal projects. The R API is greatly appreciated. Thanks for alerting me to it.
- rilut 6y agoReally want to use this for EDA. I hope it has support for client apps like DBeaver or something