collection
Memory optimized data type to be used inside of plpglsql func
pgcollection : Memory optimized data type to be used inside of plpglsql func
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 3690 | collection | pgcollection | 2.0.0 |
TYPE | Apache-2.0 | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-r | No | Yes | No | Yes | yes | no |
| Relationships | |
|---|---|
| See Also | pgbson intarray hstore arraymath pgjq jsquery pg_jsonschema jsonschema floatvec pg_projection |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 2.0.0 |
18 17 16 15 14 | pgcollection |
- |
| RPM | PIGSTY | 2.0.0 |
18 17 16 15 14 | pgcollection_$v |
- |
| DEB | PIGSTY | 2.0.0 |
18 17 16 15 14 | postgresql-$v-collection |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
| el8.aarch64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
| el9.x86_64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
| el9.aarch64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
| el10.x86_64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
| el10.aarch64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
| d12.x86_64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
| d12.aarch64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
| d13.x86_64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
| d13.aarch64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
| u22.x86_64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
| u22.aarch64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
| u24.x86_64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
| u24.aarch64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
| u26.x86_64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
| u26.aarch64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
Source
github.com/aws/pgcollection
pgcollection-2.0.0.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
Usage
The collection extension provides two memory-optimized collection data types for use within PL/pgSQL functions.
Data Types
collection: Key-value pairs with text keys (max 32,767 chars), stored in creation ordericollection: Key-value pairs with 64-bit integer keys, enabling sparse arrays
Both types support type modifiers to specify element types:
Subscript Access
Core Functions
| Function | Description |
|---|---|
add(coll, key, value) |
Add element |
count(coll) |
Element count |
delete(coll, key) |
Remove element |
exist(coll, key) |
Check key existence |
find(coll, key) |
Retrieve value |
first(coll) |
Move iterator to start |
last(coll) |
Move iterator to end |
next(coll) |
Advance iterator |
prev(coll) |
Reverse iterator |
key(coll) |
Current key |
value(coll) |
Current value |
copy(coll) |
Create copy |
sort(coll) |
Sort by keys |
keys_to_table(coll) |
All keys as set |
values_to_table(coll) |
All values as set |
to_table(coll) |
Keys and values as table |
Iterator Example
Sparse Arrays (icollection)
icollection supports non-contiguous integer indices and distinguishes between NULL values and uninitialized keys: