TL;DR

  1. DuckDB and PostgreSQL are both database systems, but their programming models are very different.
  2. DuckDB naturally uses C++ ownership, RAII, exceptions, and inheritance.
  3. PostgreSQL uses MemoryContext, ereport/longjmp, and NodeTag.

The short comparison

AreaDuckDBPostgreSQL
Memory managementsmart pointer + RAIIMemoryContext
Error handlingtry/catchlongjmp
Polymorphisminheritancenode + tag

This is not a question of one model being modern and the other being obsolete. They grew out of different languages and different project histories.

Ownership and lifetime

In DuckDB, a logical operator, physical operator, expression, or catalog entry is often a C++ class. Child objects are commonly owned by unique_ptr.

That fits tree-shaped structures:

parent owns children
destroy parent
children are destroyed too

RAII extends the same idea beyond memory. A database system has file handles, locks, buffer pins, temporary state, and transaction-local objects. With RAII, cleanup is tied to object lifetime.

PostgreSQL is different. Many objects are allocated inside a MemoryContext. Lifetime is managed by resetting or deleting the whole context, not by running each object's destructor.

Error handling

DuckDB uses C++ exceptions. If the parser, binder, optimizer, or executor finds an error, it can throw. An upper layer catches the exception and turns it into a user-facing error.

PostgreSQL uses ereport and longjmp. That model works well with MemoryContext, because after an error jump PostgreSQL can clean up a whole region of memory.

C++ exceptions work naturally with RAII because stack objects run destructors during unwinding. But exceptions should stay exceptional. A database hot path should not throw exceptions for normal per-row branching.

Runtime type

DuckDB can use C++ inheritance for expressions, operators, and function data. Behavior can live on the object.

PostgreSQL more often uses Node plus NodeTag. Code checks the tag and casts to the concrete structure.

C++ inheritance gives stronger local type structure, but virtual calls, object layout, and module boundaries need care.

Node tags keep layout direct and C-friendly, but type safety depends more on convention.

Boundary

The interesting point is not that DuckDB is "more C++". The point is that a database system's language model shapes its runtime model.

DuckDB pays attention to object ownership and destructors. PostgreSQL pays attention to region lifetime and explicit tags. Both are coherent choices.