跳转到主要内容

plprql

Use PRQL in PostgreSQL - Pipelined Relational Query Language

plprql : Use PRQL in PostgreSQL - Pipelined Relational Query Language

Overview

ID Extension Package Version Category License Language
3040 plprql plprql 18.0.1 LANG Apache-2.0 Rust
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d-- No Yes No Yes no no

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
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 / PG PG18 PG17 PG16 PG15 PG14
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
u26.x86_64 PIGSTY 18.0.1 PIGSTY 18.0.1 PIGSTY 18.0.1 PIGSTY 18.0.1 PIGSTY 18.0.1
u26.aarch64 PIGSTY 18.0.1 PIGSTY 18.0.1 PIGSTY 18.0.1 PIGSTY 18.0.1 PIGSTY 18.0.1
Package Version OS ORG SIZE File URL
plprql_18 18.0.1 el8.x86_64 pigsty 3.9 MiB plprql_18-18.0.1-4PIGSTY.el8.x86_64.rpm
plprql_18 18.0.1 el8.aarch64 pigsty 3.5 MiB plprql_18-18.0.1-4PIGSTY.el8.aarch64.rpm
plprql_18 18.0.1 el9.x86_64 pigsty 3.8 MiB plprql_18-18.0.1-4PIGSTY.el9.x86_64.rpm
plprql_18 18.0.1 el9.aarch64 pigsty 3.6 MiB plprql_18-18.0.1-4PIGSTY.el9.aarch64.rpm
plprql_18 18.0.1 el10.x86_64 pigsty 3.8 MiB plprql_18-18.0.1-4PIGSTY.el10.x86_64.rpm
plprql_18 18.0.1 el10.aarch64 pigsty 3.6 MiB plprql_18-18.0.1-4PIGSTY.el10.aarch64.rpm
postgresql-18-plprql 18.0.1 d12.x86_64 pigsty 3.1 MiB postgresql-18-plprql_18.0.1-4PIGSTY~bookworm_amd64.deb
postgresql-18-plprql 18.0.1 d12.aarch64 pigsty 2.7 MiB postgresql-18-plprql_18.0.1-4PIGSTY~bookworm_arm64.deb
postgresql-18-plprql 18.0.1 d13.x86_64 pigsty 3.1 MiB postgresql-18-plprql_18.0.1-4PIGSTY~trixie_amd64.deb
postgresql-18-plprql 18.0.1 d13.aarch64 pigsty 2.7 MiB postgresql-18-plprql_18.0.1-4PIGSTY~trixie_arm64.deb
postgresql-18-plprql 18.0.1 u22.x86_64 pigsty 3.4 MiB postgresql-18-plprql_18.0.1-4PIGSTY~jammy_amd64.deb
postgresql-18-plprql 18.0.1 u22.aarch64 pigsty 3.2 MiB postgresql-18-plprql_18.0.1-4PIGSTY~jammy_arm64.deb
postgresql-18-plprql 18.0.1 u24.x86_64 pigsty 3.4 MiB postgresql-18-plprql_18.0.1-4PIGSTY~noble_amd64.deb
postgresql-18-plprql 18.0.1 u24.aarch64 pigsty 3.2 MiB postgresql-18-plprql_18.0.1-4PIGSTY~noble_arm64.deb
postgresql-18-plprql 18.0.1 u26.x86_64 pigsty 3.4 MiB postgresql-18-plprql_18.0.1-4PIGSTY~resolute_amd64.deb
postgresql-18-plprql 18.0.1 u26.aarch64 pigsty 3.2 MiB postgresql-18-plprql_18.0.1-4PIGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
plprql_17 18.0.1 el8.x86_64 pigsty 3.9 MiB plprql_17-18.0.1-4PIGSTY.el8.x86_64.rpm
plprql_17 18.0.1 el8.aarch64 pigsty 3.5 MiB plprql_17-18.0.1-4PIGSTY.el8.aarch64.rpm
plprql_17 18.0.1 el9.x86_64 pigsty 3.7 MiB plprql_17-18.0.1-4PIGSTY.el9.x86_64.rpm
plprql_17 18.0.1 el9.aarch64 pigsty 3.6 MiB plprql_17-18.0.1-4PIGSTY.el9.aarch64.rpm
plprql_17 18.0.1 el10.x86_64 pigsty 3.8 MiB plprql_17-18.0.1-4PIGSTY.el10.x86_64.rpm
plprql_17 18.0.1 el10.aarch64 pigsty 3.6 MiB plprql_17-18.0.1-4PIGSTY.el10.aarch64.rpm
postgresql-17-plprql 18.0.1 d12.x86_64 pigsty 3.1 MiB postgresql-17-plprql_18.0.1-4PIGSTY~bookworm_amd64.deb
postgresql-17-plprql 18.0.1 d12.aarch64 pigsty 2.7 MiB postgresql-17-plprql_18.0.1-4PIGSTY~bookworm_arm64.deb
postgresql-17-plprql 18.0.1 d13.x86_64 pigsty 3.1 MiB postgresql-17-plprql_18.0.1-4PIGSTY~trixie_amd64.deb
postgresql-17-plprql 18.0.1 d13.aarch64 pigsty 2.7 MiB postgresql-17-plprql_18.0.1-4PIGSTY~trixie_arm64.deb
postgresql-17-plprql 18.0.1 u22.x86_64 pigsty 3.4 MiB postgresql-17-plprql_18.0.1-4PIGSTY~jammy_amd64.deb
postgresql-17-plprql 18.0.1 u22.aarch64 pigsty 3.2 MiB postgresql-17-plprql_18.0.1-4PIGSTY~jammy_arm64.deb
postgresql-17-plprql 18.0.1 u24.x86_64 pigsty 3.4 MiB postgresql-17-plprql_18.0.1-4PIGSTY~noble_amd64.deb
postgresql-17-plprql 18.0.1 u24.aarch64 pigsty 3.2 MiB postgresql-17-plprql_18.0.1-4PIGSTY~noble_arm64.deb
postgresql-17-plprql 18.0.1 u26.x86_64 pigsty 3.4 MiB postgresql-17-plprql_18.0.1-4PIGSTY~resolute_amd64.deb
postgresql-17-plprql 18.0.1 u26.aarch64 pigsty 3.2 MiB postgresql-17-plprql_18.0.1-4PIGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
plprql_16 18.0.1 el8.x86_64 pigsty 3.9 MiB plprql_16-18.0.1-4PIGSTY.el8.x86_64.rpm
plprql_16 18.0.1 el8.aarch64 pigsty 3.5 MiB plprql_16-18.0.1-4PIGSTY.el8.aarch64.rpm
plprql_16 18.0.1 el9.x86_64 pigsty 3.8 MiB plprql_16-18.0.1-4PIGSTY.el9.x86_64.rpm
plprql_16 18.0.1 el9.aarch64 pigsty 3.6 MiB plprql_16-18.0.1-4PIGSTY.el9.aarch64.rpm
plprql_16 18.0.1 el10.x86_64 pigsty 3.8 MiB plprql_16-18.0.1-4PIGSTY.el10.x86_64.rpm
plprql_16 18.0.1 el10.aarch64 pigsty 3.6 MiB plprql_16-18.0.1-4PIGSTY.el10.aarch64.rpm
postgresql-16-plprql 18.0.1 d12.x86_64 pigsty 3.1 MiB postgresql-16-plprql_18.0.1-4PIGSTY~bookworm_amd64.deb
postgresql-16-plprql 18.0.1 d12.aarch64 pigsty 2.7 MiB postgresql-16-plprql_18.0.1-4PIGSTY~bookworm_arm64.deb
postgresql-16-plprql 18.0.1 d13.x86_64 pigsty 3.1 MiB postgresql-16-plprql_18.0.1-4PIGSTY~trixie_amd64.deb
postgresql-16-plprql 18.0.1 d13.aarch64 pigsty 2.7 MiB postgresql-16-plprql_18.0.1-4PIGSTY~trixie_arm64.deb
postgresql-16-plprql 18.0.1 u22.x86_64 pigsty 3.4 MiB postgresql-16-plprql_18.0.1-4PIGSTY~jammy_amd64.deb
postgresql-16-plprql 18.0.1 u22.aarch64 pigsty 3.2 MiB postgresql-16-plprql_18.0.1-4PIGSTY~jammy_arm64.deb
postgresql-16-plprql 18.0.1 u24.x86_64 pigsty 3.4 MiB postgresql-16-plprql_18.0.1-4PIGSTY~noble_amd64.deb
postgresql-16-plprql 18.0.1 u24.aarch64 pigsty 3.2 MiB postgresql-16-plprql_18.0.1-4PIGSTY~noble_arm64.deb
postgresql-16-plprql 18.0.1 u26.x86_64 pigsty 3.4 MiB postgresql-16-plprql_18.0.1-4PIGSTY~resolute_amd64.deb
postgresql-16-plprql 18.0.1 u26.aarch64 pigsty 3.1 MiB postgresql-16-plprql_18.0.1-4PIGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
plprql_15 18.0.1 el8.x86_64 pigsty 3.9 MiB plprql_15-18.0.1-4PIGSTY.el8.x86_64.rpm
plprql_15 18.0.1 el8.aarch64 pigsty 3.5 MiB plprql_15-18.0.1-4PIGSTY.el8.aarch64.rpm
plprql_15 18.0.1 el9.x86_64 pigsty 3.7 MiB plprql_15-18.0.1-4PIGSTY.el9.x86_64.rpm
plprql_15 18.0.1 el9.aarch64 pigsty 3.6 MiB plprql_15-18.0.1-4PIGSTY.el9.aarch64.rpm
plprql_15 18.0.1 el10.x86_64 pigsty 3.7 MiB plprql_15-18.0.1-4PIGSTY.el10.x86_64.rpm
plprql_15 18.0.1 el10.aarch64 pigsty 3.6 MiB plprql_15-18.0.1-4PIGSTY.el10.aarch64.rpm
postgresql-15-plprql 18.0.1 d12.x86_64 pigsty 3.1 MiB postgresql-15-plprql_18.0.1-4PIGSTY~bookworm_amd64.deb
postgresql-15-plprql 18.0.1 d12.aarch64 pigsty 2.7 MiB postgresql-15-plprql_18.0.1-4PIGSTY~bookworm_arm64.deb
postgresql-15-plprql 18.0.1 d13.x86_64 pigsty 3.1 MiB postgresql-15-plprql_18.0.1-4PIGSTY~trixie_amd64.deb
postgresql-15-plprql 18.0.1 d13.aarch64 pigsty 2.7 MiB postgresql-15-plprql_18.0.1-4PIGSTY~trixie_arm64.deb
postgresql-15-plprql 18.0.1 u22.x86_64 pigsty 3.4 MiB postgresql-15-plprql_18.0.1-4PIGSTY~jammy_amd64.deb
postgresql-15-plprql 18.0.1 u22.aarch64 pigsty 3.2 MiB postgresql-15-plprql_18.0.1-4PIGSTY~jammy_arm64.deb
postgresql-15-plprql 18.0.1 u24.x86_64 pigsty 3.4 MiB postgresql-15-plprql_18.0.1-4PIGSTY~noble_amd64.deb
postgresql-15-plprql 18.0.1 u24.aarch64 pigsty 3.2 MiB postgresql-15-plprql_18.0.1-4PIGSTY~noble_arm64.deb
postgresql-15-plprql 18.0.1 u26.x86_64 pigsty 3.4 MiB postgresql-15-plprql_18.0.1-4PIGSTY~resolute_amd64.deb
postgresql-15-plprql 18.0.1 u26.aarch64 pigsty 3.1 MiB postgresql-15-plprql_18.0.1-4PIGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
plprql_14 18.0.1 el8.x86_64 pigsty 3.9 MiB plprql_14-18.0.1-4PIGSTY.el8.x86_64.rpm
plprql_14 18.0.1 el8.aarch64 pigsty 3.5 MiB plprql_14-18.0.1-4PIGSTY.el8.aarch64.rpm
plprql_14 18.0.1 el9.x86_64 pigsty 3.7 MiB plprql_14-18.0.1-4PIGSTY.el9.x86_64.rpm
plprql_14 18.0.1 el9.aarch64 pigsty 3.6 MiB plprql_14-18.0.1-4PIGSTY.el9.aarch64.rpm
plprql_14 18.0.1 el10.x86_64 pigsty 3.7 MiB plprql_14-18.0.1-4PIGSTY.el10.x86_64.rpm
plprql_14 18.0.1 el10.aarch64 pigsty 3.6 MiB plprql_14-18.0.1-4PIGSTY.el10.aarch64.rpm
postgresql-14-plprql 18.0.1 d12.x86_64 pigsty 3.1 MiB postgresql-14-plprql_18.0.1-4PIGSTY~bookworm_amd64.deb
postgresql-14-plprql 18.0.1 d12.aarch64 pigsty 2.7 MiB postgresql-14-plprql_18.0.1-4PIGSTY~bookworm_arm64.deb
postgresql-14-plprql 18.0.1 d13.x86_64 pigsty 3.1 MiB postgresql-14-plprql_18.0.1-4PIGSTY~trixie_amd64.deb
postgresql-14-plprql 18.0.1 d13.aarch64 pigsty 2.7 MiB postgresql-14-plprql_18.0.1-4PIGSTY~trixie_arm64.deb
postgresql-14-plprql 18.0.1 u22.x86_64 pigsty 3.4 MiB postgresql-14-plprql_18.0.1-4PIGSTY~jammy_amd64.deb
postgresql-14-plprql 18.0.1 u22.aarch64 pigsty 3.2 MiB postgresql-14-plprql_18.0.1-4PIGSTY~jammy_arm64.deb
postgresql-14-plprql 18.0.1 u24.x86_64 pigsty 3.4 MiB postgresql-14-plprql_18.0.1-4PIGSTY~noble_amd64.deb
postgresql-14-plprql 18.0.1 u24.aarch64 pigsty 3.2 MiB postgresql-14-plprql_18.0.1-4PIGSTY~noble_arm64.deb
postgresql-14-plprql 18.0.1 u26.x86_64 pigsty 3.4 MiB postgresql-14-plprql_18.0.1-4PIGSTY~resolute_amd64.deb
postgresql-14-plprql 18.0.1 u26.aarch64 pigsty 3.1 MiB postgresql-14-plprql_18.0.1-4PIGSTY~resolute_arm64.deb

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.