跳转到主要内容

omni_python

Omnigres 第一类Python支持模块

概览

扩展包名版本分类许可证语言
omnigres0.1.1FEATApache-2.0C
ID扩展名BinLibLoadCreateTrustReloc模式
2940omni否是是是否否omni
2941omni_auth否否否是否否omni_auth
2942omni_aws否否否是是否omni_aws
2943omni_cloudevents否否否是是否omni_cloudevents
2944omni_containers否是否是否否omni_containers
2945omni_credentials否否否是否否omni_credentials
2948omni_email否否否是否否omni_email
2949omni_http否否否是否否omni_http
2950omni_httpc否是否是否否omni_httpc
2951omni_httpd否是否是否否omni_httpd
2952omni_id否是否是否是-
2953omni_json否否否是是否omni_json
2954omni_kube否是否是否否omni_kube
2955omni_ledger否是否是否否omni_ledger
2956omni_manifest否否否是否否omni_manifest
2957omni_mimetypes否否否是否否omni_mimetypes
2958omni_os否是否是否否omni_os
2959omni_polyfill否是否是否否omni_polyfill
2960omni_python否是否是否否omni_python
2961omni_regex否是否是否是-
2962omni_rest否否否是否否omni_rest
2963omni_schema否否否是否否omni_schema
2964omni_seq否是否是否否omni_seq
2965omni_service否否否是否否omni_service
2966omni_session否否否是否否omni_session
2968omni_sql否是否是否否omni_sql
2969omni_sqlite否是否是否否omni_sqlite
2970omni_test否否否是否否omni_test
2971omni_txn否是否是否否omni_txn
2972omni_types否是否是否否omni_types
2973omni_var否是否是否否omni_var
2974omni_vfs否是否是否否omni_vfs
2975omni_vfs_types_v1否否否是否否omni_vfs_types_v1
2976omni_web否是否是否否omni_web
2977omni_worker否是否是否否omni_worker
2978omni_xml否是否是否否omni_xml
2979omni_yaml否是否是否否omni_yaml

版本

类型仓库版本PG 大版本包名依赖
EXTPIGSTY0.1.11817161514omnigresplpython3u
RPMPIGSTY202602121817161514omnigres_$vpostgresql$v-contrib, postgresql$v-plpython3, python3-pip
DEBPIGSTY202602121817161514postgresql-$v-omnigrespostgresql-plpython3-$v, python3-pip
OS / PGPG18PG17PG16PG15PG14
el8.x86_64PIGSTY 20251108PIGSTY 20250120PIGSTY 20250120PIGSTY 20250120PIGSTY 20250120
el8.aarch64PIGSTY 20251108PIGSTY 20250120PIGSTY 20250120PIGSTY 20250120PIGSTY 20250120
el9.x86_64PIGSTY 20251108PIGSTY 20250507PIGSTY 20250507PIGSTY 20250507PIGSTY 20250507
el9.aarch64PIGSTY 20251108PIGSTY 20250507PIGSTY 20250507PIGSTY 20250507PIGSTY 20250507
el10.x86_64PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108
el10.aarch64PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108
d12.x86_64PIGSTY 20251108PIGSTY 20250120PIGSTY 20250120PIGSTY 20250120PIGSTY 20250120
d12.aarch64PIGSTY 20251108PIGSTY 20250120PIGSTY 20250120PIGSTY 20250120PIGSTY 20250120
d13.x86_64PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108
d13.aarch64PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108
u22.x86_64PIGSTY 20251108PIGSTY 20250120PIGSTY 20250120PIGSTY 20250120PIGSTY 20250120
u22.aarch64PIGSTY 20251108PIGSTY 20250120PIGSTY 20250120PIGSTY 20250120PIGSTY 20250120
u24.x86_64PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108
u24.aarch64PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108
u26.x86_64PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108
u26.aarch64PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108PIGSTY 20251108

构建

您可以使用 pig build 命令构建 omnigres 扩展的 RPM / DEB 包:

pig build pkg omnigres         # 构建 RPM / DEB 包

安装

您可以直接安装 omnigres 扩展包的预置二进制包,首先确保 PGDG 和 PIGSTY 仓库已经添加并启用:

pig repo add pgsql -u          # 添加仓库并更新缓存

使用 pig 或者是 apt/yum/dnf 安装扩展:

安装
pig install omnigres;          # 当前活跃 PG 版本安装
pig
pig ext install -y omnigres -v 18  # PG 18
pig ext install -y omnigres -v 17  # PG 17
pig ext install -y omnigres -v 16  # PG 16
pig ext install -y omnigres -v 15  # PG 15
pig ext install -y omnigres -v 14  # PG 14
dnf
dnf install -y omnigres_18       # PG 18
dnf install -y omnigres_17       # PG 17
dnf install -y omnigres_16       # PG 16
dnf install -y omnigres_15       # PG 15
dnf install -y omnigres_14       # PG 14
apt
apt install -y postgresql-18-omnigres   # PG 18
apt install -y postgresql-17-omnigres   # PG 17
apt install -y postgresql-16-omnigres   # PG 16
apt install -y postgresql-15-omnigres   # PG 15
apt install -y postgresql-14-omnigres   # PG 14

创建扩展:

CREATE EXTENSION omni_python CASCADE;  -- 依赖: plpython3u

用法

omni_python: 一等 Python 支持

omni_python 扩展将 Python 代码作为存储过程集成到 PostgreSQL 中。

基本 Python 函数

创建带 @pg 装饰器的 Python 文件:

# hello.py
from omni_python import pg

@pg
def hello() -> str:
    return "Hey there!"

@pg
def add(a: int, b: int) -> int:
    return a + b

加载 Python 文件

CREATE EXTENSION omni_python CASCADE;
CREATE EXTENSION omni_schema CASCADE;
CREATE EXTENSION omni_vfs CASCADE;

CREATE OR REPLACE FUNCTION demo_fs() RETURNS omni_vfs.local_fs
    LANGUAGE sql AS $$ SELECT omni_vfs.local_fs('/python-files') $$;

SELECT omni_schema.load_from_fs(demo_fs());

Flask 集成

from omni_python import pg
from omni_http import omni_httpd
from omni_http.omni_httpd import flask
from flask import Flask, jsonify, request

app = Flask('myapp')

@app.route('/employees', methods=['GET'])
def get_employees():
    employees = plpy.execute(plpy.prepare("select * from employees"))
    return json.dumps([dict(e) for e in employees])

handle = pg(flask.Adapter(app))

配置 HTTP 处理器:

UPDATE omni_httpd.handlers SET query = $$select handle(request.*) from request$$;

这个页面对您有帮助吗?