跳转到主要内容

plprql

在PostgreSQL使用PRQL——管线式关系查询语言

plprql · 在PostgreSQL使用PRQL——管线式关系查询语言

概览

ID扩展软件包版本类别许可证编程语言
3040plprqlplprql18.0.2LANGApache-2.0Rust
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--s-d--否是否是否否

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY18.0.219 18 17 16 15plprql-
RPMPIGSTY18.0.219 18 17 16 15plprql_$v-
DEBPIGSTY18.0.219 18 17 16 15postgresql-$v-plprql-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2
el8.aarch64N/APIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2
el9.x86_64PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2
el9.aarch64PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2
el10.x86_64PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2
el10.aarch64PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2
d12.x86_64PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2
d12.aarch64PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2
d13.x86_64PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2
d13.aarch64PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2
u22.x86_64PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2
u22.aarch64PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2
u24.x86_64PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2
u24.aarch64PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2
u26.x86_64PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2
u26.aarch64PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2PIGSTY 18.0.2
软件包版本平台仓库大小下载
plprql_1818.0.2el8.x86_64pigsty4.0 MiBplprql_18-18.0.2-1PGSTY.el8.x86_64.rpm
plprql_1818.0.2el8.aarch64pigsty3.5 MiBplprql_18-18.0.2-1PGSTY.el8.aarch64.rpm
plprql_1818.0.2el9.x86_64pigsty4.8 MiBplprql_18-18.0.2-2PGSTY.el9.x86_64.rpm
plprql_1818.0.2el9.aarch64pigsty4.5 MiBplprql_18-18.0.2-2PGSTY.el9.aarch64.rpm
plprql_1818.0.2el10.x86_64pigsty4.8 MiBplprql_18-18.0.2-2PGSTY.el10.x86_64.rpm
plprql_1818.0.2el10.aarch64pigsty4.5 MiBplprql_18-18.0.2-2PGSTY.el10.aarch64.rpm
postgresql-18-plprql18.0.2d12.x86_64pigsty3.1 MiBpostgresql-18-plprql_18.0.2-2PGSTY~bookworm_amd64.deb
postgresql-18-plprql18.0.2d12.aarch64pigsty2.7 MiBpostgresql-18-plprql_18.0.2-2PGSTY~bookworm_arm64.deb
postgresql-18-plprql18.0.2d13.x86_64pigsty3.1 MiBpostgresql-18-plprql_18.0.2-2PGSTY~trixie_amd64.deb
postgresql-18-plprql18.0.2d13.aarch64pigsty2.7 MiBpostgresql-18-plprql_18.0.2-2PGSTY~trixie_arm64.deb
postgresql-18-plprql18.0.2u22.x86_64pigsty3.5 MiBpostgresql-18-plprql_18.0.2-2PGSTY~jammy_amd64.deb
postgresql-18-plprql18.0.2u22.aarch64pigsty3.3 MiBpostgresql-18-plprql_18.0.2-2PGSTY~jammy_arm64.deb
postgresql-18-plprql18.0.2u24.x86_64pigsty3.5 MiBpostgresql-18-plprql_18.0.2-2PGSTY~noble_amd64.deb
postgresql-18-plprql18.0.2u24.aarch64pigsty3.3 MiBpostgresql-18-plprql_18.0.2-2PGSTY~noble_arm64.deb
postgresql-18-plprql18.0.2u26.x86_64pigsty3.4 MiBpostgresql-18-plprql_18.0.2-2PGSTY~resolute_amd64.deb
postgresql-18-plprql18.0.2u26.aarch64pigsty3.3 MiBpostgresql-18-plprql_18.0.2-2PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
plprql_1718.0.2el8.x86_64pigsty4.0 MiBplprql_17-18.0.2-1PGSTY.el8.x86_64.rpm
plprql_1718.0.2el8.aarch64pigsty3.5 MiBplprql_17-18.0.2-1PGSTY.el8.aarch64.rpm
plprql_1718.0.2el9.x86_64pigsty4.8 MiBplprql_17-18.0.2-2PGSTY.el9.x86_64.rpm
plprql_1718.0.2el9.aarch64pigsty4.5 MiBplprql_17-18.0.2-2PGSTY.el9.aarch64.rpm
plprql_1718.0.2el10.x86_64pigsty4.8 MiBplprql_17-18.0.2-2PGSTY.el10.x86_64.rpm
plprql_1718.0.2el10.aarch64pigsty4.5 MiBplprql_17-18.0.2-2PGSTY.el10.aarch64.rpm
postgresql-17-plprql18.0.2d12.x86_64pigsty3.1 MiBpostgresql-17-plprql_18.0.2-2PGSTY~bookworm_amd64.deb
postgresql-17-plprql18.0.2d12.aarch64pigsty2.7 MiBpostgresql-17-plprql_18.0.2-2PGSTY~bookworm_arm64.deb
postgresql-17-plprql18.0.2d13.x86_64pigsty3.1 MiBpostgresql-17-plprql_18.0.2-2PGSTY~trixie_amd64.deb
postgresql-17-plprql18.0.2d13.aarch64pigsty2.7 MiBpostgresql-17-plprql_18.0.2-2PGSTY~trixie_arm64.deb
postgresql-17-plprql18.0.2u22.x86_64pigsty3.5 MiBpostgresql-17-plprql_18.0.2-2PGSTY~jammy_amd64.deb
postgresql-17-plprql18.0.2u22.aarch64pigsty3.3 MiBpostgresql-17-plprql_18.0.2-2PGSTY~jammy_arm64.deb
postgresql-17-plprql18.0.2u24.x86_64pigsty3.5 MiBpostgresql-17-plprql_18.0.2-2PGSTY~noble_amd64.deb
postgresql-17-plprql18.0.2u24.aarch64pigsty3.3 MiBpostgresql-17-plprql_18.0.2-2PGSTY~noble_arm64.deb
postgresql-17-plprql18.0.2u26.x86_64pigsty3.4 MiBpostgresql-17-plprql_18.0.2-2PGSTY~resolute_amd64.deb
postgresql-17-plprql18.0.2u26.aarch64pigsty3.2 MiBpostgresql-17-plprql_18.0.2-2PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
plprql_1618.0.2el8.x86_64pigsty4.0 MiBplprql_16-18.0.2-1PGSTY.el8.x86_64.rpm
plprql_1618.0.2el8.aarch64pigsty3.5 MiBplprql_16-18.0.2-1PGSTY.el8.aarch64.rpm
plprql_1618.0.2el9.x86_64pigsty4.8 MiBplprql_16-18.0.2-2PGSTY.el9.x86_64.rpm
plprql_1618.0.2el9.aarch64pigsty4.5 MiBplprql_16-18.0.2-2PGSTY.el9.aarch64.rpm
plprql_1618.0.2el10.x86_64pigsty4.8 MiBplprql_16-18.0.2-2PGSTY.el10.x86_64.rpm
plprql_1618.0.2el10.aarch64pigsty4.5 MiBplprql_16-18.0.2-2PGSTY.el10.aarch64.rpm
postgresql-16-plprql18.0.2d12.x86_64pigsty3.1 MiBpostgresql-16-plprql_18.0.2-2PGSTY~bookworm_amd64.deb
postgresql-16-plprql18.0.2d12.aarch64pigsty2.7 MiBpostgresql-16-plprql_18.0.2-2PGSTY~bookworm_arm64.deb
postgresql-16-plprql18.0.2d13.x86_64pigsty3.1 MiBpostgresql-16-plprql_18.0.2-2PGSTY~trixie_amd64.deb
postgresql-16-plprql18.0.2d13.aarch64pigsty2.7 MiBpostgresql-16-plprql_18.0.2-2PGSTY~trixie_arm64.deb
postgresql-16-plprql18.0.2u22.x86_64pigsty3.5 MiBpostgresql-16-plprql_18.0.2-2PGSTY~jammy_amd64.deb
postgresql-16-plprql18.0.2u22.aarch64pigsty3.3 MiBpostgresql-16-plprql_18.0.2-2PGSTY~jammy_arm64.deb
postgresql-16-plprql18.0.2u24.x86_64pigsty3.5 MiBpostgresql-16-plprql_18.0.2-2PGSTY~noble_amd64.deb
postgresql-16-plprql18.0.2u24.aarch64pigsty3.3 MiBpostgresql-16-plprql_18.0.2-2PGSTY~noble_arm64.deb
postgresql-16-plprql18.0.2u26.x86_64pigsty3.4 MiBpostgresql-16-plprql_18.0.2-2PGSTY~resolute_amd64.deb
postgresql-16-plprql18.0.2u26.aarch64pigsty3.2 MiBpostgresql-16-plprql_18.0.2-2PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
plprql_1518.0.2el8.x86_64pigsty4.0 MiBplprql_15-18.0.2-1PGSTY.el8.x86_64.rpm
plprql_1518.0.2el8.aarch64pigsty3.5 MiBplprql_15-18.0.2-1PGSTY.el8.aarch64.rpm
plprql_1518.0.2el9.x86_64pigsty4.8 MiBplprql_15-18.0.2-2PGSTY.el9.x86_64.rpm
plprql_1518.0.2el9.aarch64pigsty4.5 MiBplprql_15-18.0.2-2PGSTY.el9.aarch64.rpm
plprql_1518.0.2el10.x86_64pigsty4.8 MiBplprql_15-18.0.2-2PGSTY.el10.x86_64.rpm
plprql_1518.0.2el10.aarch64pigsty4.5 MiBplprql_15-18.0.2-2PGSTY.el10.aarch64.rpm
postgresql-15-plprql18.0.2d12.x86_64pigsty3.1 MiBpostgresql-15-plprql_18.0.2-2PGSTY~bookworm_amd64.deb
postgresql-15-plprql18.0.2d12.aarch64pigsty2.7 MiBpostgresql-15-plprql_18.0.2-2PGSTY~bookworm_arm64.deb
postgresql-15-plprql18.0.2d13.x86_64pigsty3.1 MiBpostgresql-15-plprql_18.0.2-2PGSTY~trixie_amd64.deb
postgresql-15-plprql18.0.2d13.aarch64pigsty2.7 MiBpostgresql-15-plprql_18.0.2-2PGSTY~trixie_arm64.deb
postgresql-15-plprql18.0.2u22.x86_64pigsty3.5 MiBpostgresql-15-plprql_18.0.2-2PGSTY~jammy_amd64.deb
postgresql-15-plprql18.0.2u22.aarch64pigsty3.3 MiBpostgresql-15-plprql_18.0.2-2PGSTY~jammy_arm64.deb
postgresql-15-plprql18.0.2u24.x86_64pigsty3.5 MiBpostgresql-15-plprql_18.0.2-2PGSTY~noble_amd64.deb
postgresql-15-plprql18.0.2u24.aarch64pigsty3.3 MiBpostgresql-15-plprql_18.0.2-2PGSTY~noble_arm64.deb
postgresql-15-plprql18.0.2u26.x86_64pigsty3.4 MiBpostgresql-15-plprql_18.0.2-2PGSTY~resolute_amd64.deb
postgresql-15-plprql18.0.2u26.aarch64pigsty3.2 MiBpostgresql-15-plprql_18.0.2-2PGSTY~resolute_arm64.deb

源码

pig build pkg plprql;		# build rpm/deb

安装

启用 PGDG 和 PIGSTY 仓库并更新缓存。

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

使用 pig 安装扩展。

pig install plprql;		# install by package name

pig install plprql -v 19;   # install for PG 19
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

在数据库中创建扩展。

CREATE EXTENSION plprql;

用法

plprql: 在 PostgreSQL 中使用 PRQL —— 管道式关系查询语言

plprql 允许使用 PRQL(管道式关系查询语言)编写 PostgreSQL 函数,这是一种编译为 SQL 的现代语言,采用管道语法。

CREATE EXTENSION plprql;

使用 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);

直接执行 PRQL

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

使用游标处理大结果集

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

查看编译后的 SQL

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

PRQL 语法概览

PRQL 使用管道式转换:

from employees                    # 数据源
filter department == "Engineering" # 行过滤
derive monthly_salary = salary / 12 # 计算列
sort {-monthly_salary}            # 排序(- 表示降序)
select {name, monthly_salary}     # 列投影
take 10                           # 限制行数

限制

PRQL 仅支持 SELECT 语句。对于 INSERT、UPDATE 和 DELETE,请使用 SQL 或 PL/pgSQL。

表格阅读器