collection
面向高性能 PL/pgSQL 工作流的关联数组数据类型
pgcollection · 面向高性能 PL/pgSQL 工作流的关联数组数据类型
概览
| ID | 扩展 | 软件包 | 版本 | 类别 | 许可证 | 编程语言 |
|---|---|---|---|---|---|---|
| 3700 | collection | pgcollection | 2.1.3 | TYPE | Apache-2.0 | C |
| 属性 | 可执行文件 | 动态库 | 需要预加载 | 需要建扩展 | 可迁移 | 可信 |
|---|---|---|---|---|---|---|
| --s-d-r | 否 | 是 | 否 | 是 | 是 | 否 |
| 关联 | |
|---|---|
| 相关扩展 | pgbson intarray hstore arraymath pgjq jsquery pg_jsonschema jsonschema floatvec pg_projection istore |
PGXN name: pgcollection.
软件包
| Linux / PG | PG19 | PG18 | PG17 | PG16 | PG15 |
|---|---|---|---|---|---|
| el8.x86_64 | N/A | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 |
| el8.aarch64 | N/A | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 |
| el9.x86_64 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 |
| el9.aarch64 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 |
| el10.x86_64 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 |
| el10.aarch64 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 |
| d12.x86_64 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 |
| d12.aarch64 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 |
| d13.x86_64 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 |
| d13.aarch64 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 |
| u22.x86_64 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 |
| u22.aarch64 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 |
| u24.x86_64 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 |
| u24.aarch64 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 |
| u26.x86_64 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 |
| u26.aarch64 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 | PIGSTY 2.1.3 |
源码
安装
在数据库中创建扩展。
用法
collection 扩展提供了两种内存优化的集合数据类型,用于 PL/pgSQL 函数中。
数据类型
collection:文本键的键值对(最长 32,767 字符),按创建顺序存储icollection:64 位整数键的键值对,支持稀疏数组
两种类型都支持类型修饰符来指定元素类型:
下标访问
核心函数
| 函数 | 说明 |
|---|---|
add(coll, key, value) | 添加元素 |
count(coll) | 元素数量 |
delete(coll, key) | 删除元素 |
exist(coll, key) | 检查键是否存在 |
find(coll, key) | 获取值 |
first(coll) | 将迭代器移至起始位置 |
last(coll) | 将迭代器移至末尾位置 |
next(coll) | 迭代器前进 |
prev(coll) | 迭代器后退 |
key(coll) | 当前键 |
value(coll) | 当前值 |
copy(coll) | 创建副本 |
sort(coll) | 按键排序 |
keys_to_table(coll) | 所有键作为集合返回 |
values_to_table(coll) | 所有值作为集合返回 |
to_table(coll) | 键值对作为表返回 |
迭代器示例
稀疏数组(icollection)
icollection 支持非连续整数索引,并能区分 NULL 值和未初始化的键: