HeadlinesBriefing favicon HeadlinesBriefing.com

Prela Query Language: 11 Lines of Code SQL Alternative

Hacker News •
×

Prela is a new query language being developed at UCLA Re PL. The language is quite different from SQL, but its key ideas are very simple. In this short tutorial, we build a toy version of Prela in Python to understand its core principles.

The query below finds every movie produced by an American company and has a character name in its title, outputting the title along with the alias for each cast member. Note that the equivalent query in SQL spans over 20 lines.

The first special thing about Prela is that there are only binary relations, i.e., tables with two columns. That may sound very limiting at first, but it's easy to "binarize" a wide table with multiple columns.

The motivation for focusing on binary relations is that they generalize functions. Functions are powerful because they compose, making them the building blocks of programs. A function maps every input to a unique output, whereas a relation can map an input to multiple different outputs. In a sense, a relation can be viewed as a nondeterministic function.

The power of composition really shows when we chain together multiple .select calls. Because joining via a foreign key almost always requires "resolving" an ID to a row, Prela automatically inserts that step so one can write the following, which reads just like "a movie's company's country"!