跳转到主要内容

omni_sqlite

Omnigres 嵌入的SQLite支持

omnigres · Omnigres 嵌入的SQLite支持

概览

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

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY0.2.219 18 17 16 15omnigres-
RPMPIGSTY2026021219 18 17 16 15omnigres_$vpostgresql$v-contrib, postgresql$v-plpython3, python3-pip
DEBPIGSTY2026021219 18 17 16 15postgresql-$v-omnigrespostgresql-plpython3-$v, python3-pip
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
el8.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
el9.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
el9.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
el10.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
el10.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
d12.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
d12.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
d13.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
d13.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
u22.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
u22.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
u24.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
u24.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
u26.x86_64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212
u26.aarch64N/APIGSTY 20260212PIGSTY 20260212PIGSTY 20260212PIGSTY 20260212

源码

pig build pkg omnigres;		# build rpm/deb

安装

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

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

使用 pig 安装扩展。

pig install omnigres;		# install by package name
pig install omni_sqlite;		# install by extension name

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

在数据库中创建扩展。

CREATE EXTENSION omni_sqlite;

用法

omni_sqlite: 内嵌 SQLite

omni_sqlite 扩展将 SQLite 数据库作为 PostgreSQL 的一等数据类型。它是一个模板化扩展。

创建 SQLite 数据库

SELECT 'CREATE TABLE user_config (key text, value text)'::omni_sqlite.sqlite;

在列中存储 SQLite

CREATE TABLE customer (
    id   bigserial PRIMARY KEY,
    name text NOT NULL,
    data omni_sqlite.sqlite DEFAULT 'CREATE TABLE user_config (key text, value text);'
);

执行语句

UPDATE customer
SET data = omni_sqlite.sqlite_exec(data,
    $$INSERT INTO user_config VALUES ('color', 'blue')$$)
RETURNING *;

带绑定参数:

SELECT omni_sqlite.sqlite_exec('CREATE TABLE tab (val text)',
    'INSERT INTO tab VALUES ($1)', row('hello'));

查询 SQLite 数据

SELECT * FROM omni_sqlite.sqlite_query(
    (SELECT data FROM customer),
    'SELECT rowid, key, value FROM user_config')
AS (id bigint, key text, value text);

序列化

-- 序列化为 bytea:
SELECT omni_sqlite.sqlite_serialize('CREATE TABLE foo (x)');
-- 从 bytea 反序列化:
SELECT omni_sqlite.sqlite_deserialize(bytea_data);

适用于多租户(每行隔离的 SQLite 数据库)和对等同步场景。

表格阅读器