plprql

plprql : Use PRQL in PostgreSQL - Pipelined Relational Query Language

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
3040
plprql
plprql
18.0.1
LANG
Apache-2.0
Rust
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d--
No
Yes
No
Yes
no
no
Relationships
See Also
pg_tle
plpgsql
plv8
plperl
plpython3u
pllua
hstore_pllua
plluau

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PIGSTY
18.0.1
18
17
16
15
14
plprql-
RPM
PIGSTY
18.0.1
18
17
16
15
14
plprql_$v-
DEB
PIGSTY
18.0.1
18
17
16
15
14
postgresql-$v-plprql-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
el8.aarch64
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
el9.x86_64
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
el9.aarch64
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
el10.x86_64
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
el10.aarch64
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
d12.x86_64
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
d12.aarch64
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
d13.x86_64
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
d13.aarch64
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
u22.x86_64
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
u22.aarch64
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
u24.x86_64
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
u24.aarch64
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1
PIGSTY 18.0.1

Source

pig build pkg plprql;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install plprql;		# install via package name, for the active PG version

pig install plprql -v 18;   # install for PG 18
pig install plprql -v 17;   # install for PG 17
pig install plprql -v 16;   # install for PG 16
pig install plprql -v 15;   # install for PG 15
pig install plprql -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION plprql;

Usage

plprql: Use PRQL in PostgreSQL - Pipelined Relational Query Language

plprql enables writing PostgreSQL functions using PRQL (Pipelined Relational Query Language), a modern language that compiles to SQL with a pipeline syntax.

CREATE EXTENSION plprql;

Create Functions with PRQL

CREATE FUNCTION match_stats(int)
RETURNS TABLE(player text, kd_ratio float) AS $$
  from matches
  filter match_id == $1
  group player (
    aggregate {
      total_kills = sum kills,
      total_deaths = sum deaths
    }
  )
  filter total_deaths > 0
  derive kd_ratio = total_kills / total_deaths
  select { player, kd_ratio }
$$ LANGUAGE plprql;

SELECT * FROM match_stats(42);

Execute PRQL Directly

SELECT prql('from matches | filter player == "Player1"')
  AS (id int, match_id int, player text, kills int)
  LIMIT 2;

Use Cursors for Large Results

SELECT prql('from matches | filter player == "Player1"', 'cursor_name');
FETCH 2 FROM cursor_name;

Inspect Compiled SQL

SELECT prql_to_sql('from matches | filter player == "Player1"');

PRQL Syntax Overview

PRQL uses pipeline transformations:

from employees                    # data source
filter department == "Engineering" # row filtering
derive monthly_salary = salary / 12 # computed columns
sort {-monthly_salary}            # sorting (- for descending)
select {name, monthly_salary}     # column projection
take 10                           # limit rows

Limitations

PRQL only supports SELECT statements. For INSERT, UPDATE, and DELETE, use SQL or PL/pgSQL.

Last updated on