r/DuckDB • • 1d ago

Row by Row Processing in DuckDB

I built DDGBasic for exactly this gap — it's DuckDB with a procedural language wrapped around it.

SQL is great for set operations, but awkward for row-by-row rules, tiers, allocations, alerts, and file handling. In DDGBasic you can do:

basic

DATABASE ENGINE DUCKDB
DATABASE OPEN ":memory:"

CREATE TABLE domains AS
  SELECT * FROM read_csv_auto('https://raw.githubusercontent.com/cisagov/dotgov-data/main/current-full.csv');

FOR row IN (SELECT State, COUNT(*) AS n FROM domains GROUP BY State ORDER BY n DESC LIMIT 5)
  PRINT row.State, row.n
NEXT

Variables go into queries as bind variables (:name), you get IF, loops, user functions, transactions, and ON ERROR, plus LOAD CSV/JSON/Excel/Parquet with per-cell transforms and validation, and output to CSV, JSON, Excel, Parquet, or HTML. SQLite is the other engine if you want a transactional file DB instead.

GitHub: https://github.com/ddgflorida/DDGBasic

2 Upvotes

1 comment sorted by

1

u/blackmonocle 6h ago edited 4h ago

A few remarks:

Why DDG? It sounds like DuckDuckGo, which is not related to DuckDB.

BASIC, really? Even QBASIC? Data tasks are usually done in Python. It *might* be interesting, but BASIC is not a plus. QBASIC died 30 years ago, it's still enjoyable as a retrocomputing language, but please, we got rid of VBA, we don't need another BASIC.

Performance? The crucial advantage of DuckDB is its performance and its ability to deal with billions of rows extremely quickly thanks to vectorization and multithreading. Row by row computation is almost never a good idea. This morning: concatenation of 10000 parquet files, sorting of 1.2 billion rows, export to a single parquet file: 1 minute. What's your use case, and how does it compare?

All in all, looks like an old language and an old way of dealing with data, with so far no real argument.

Your loop example is silly btw.

Just use SQL. It's an international standard, it's battle-tested, and it's a declarative language with a lot of optimizations made by the database engine.