http

HTTP客户端,允许在数据库内收发HTTP请求 (supabase)

扩展总览

PGDG 第一方扩展: pg_http : HTTP客户端,允许在数据库内收发HTTP请求 (supabase)

基本信息

  • 扩展编号: 4070
  • 扩展名称: http
  • 标准包名: pg_http
  • 扩展类目: UTIL
  • 开源协议: MIT
  • 官方网站: https://github.com/pramsey/pgsql-http
  • 编程语言: C
  • 其他标签: supabase
  • 备注信息: 无

元数据

  • 默认版本: 1.6.3
  • PG大版本: 17,16,15,14,13
  • 动态加载: 无需动态加载
  • 需要DDL: 需要执行 CREATE EXTENSION DDL
  • 可重定位: 未知
  • 信任程度: 未受信任,创建扩展需要超级用户权限
  • 所需模式: 无
  • 所需扩展: 无

软件包

  • RPM仓库:PGDG
  • RPM包名:pgsql_http_$v*
  • RPM版本:1.6.3
  • RPM依赖:无
  • DEB仓库:PGDG
  • DEB包名:postgresql-$v-http
  • DEB版本:1.6.3
  • DEB依赖:无

最新版本

系统 架构 PG17 PG16 PG15 PG14 PG13
el8 x86_64 pgsql_http_17
PGDG 1.6.3
pgsql_http_16
PGDG 1.6.3
pgsql_http_15
PGDG 1.6.3
pgsql_http_14
PGDG 1.6.3
pgsql_http_13
PGDG 1.6.3
el8 aarch64 pgsql_http_17
PGDG 1.6.3
pgsql_http_16
PGDG 1.6.3
pgsql_http_15
PGDG 1.6.3
pgsql_http_14
PGDG 1.6.3
pgsql_http_13
PGDG 1.6.3
el9 x86_64 pgsql_http_17
PGDG 1.6.3
pgsql_http_16
PGDG 1.6.3
pgsql_http_15
PGDG 1.6.3
pgsql_http_14
PGDG 1.6.3
pgsql_http_13
PGDG 1.6.3
el9 aarch64 pgsql_http_17
PGDG 1.6.3
pgsql_http_16
PGDG 1.6.3
pgsql_http_15
PGDG 1.6.3
pgsql_http_14
PGDG 1.6.3
pgsql_http_13
PGDG 1.6.3
d12 x86_64 postgresql-17-http
PGDG 1.6.3
postgresql-16-http
PGDG 1.6.3
postgresql-15-http
PGDG 1.6.3
postgresql-14-http
PGDG 1.6.3
postgresql-13-http
PGDG 1.6.3
d12 aarch64 postgresql-17-http
PGDG 1.6.3
postgresql-16-http
PGDG 1.6.3
postgresql-15-http
PGDG 1.6.3
postgresql-14-http
PGDG 1.6.3
postgresql-13-http
PGDG 1.6.3
u22 x86_64 postgresql-17-http
PGDG 1.6.3
postgresql-16-http
PGDG 1.6.3
postgresql-15-http
PGDG 1.6.3
postgresql-14-http
PGDG 1.6.3
postgresql-13-http
PGDG 1.6.3
u22 aarch64 postgresql-17-http
PGDG 1.6.3
postgresql-16-http
PGDG 1.6.3
postgresql-15-http
PGDG 1.6.3
postgresql-14-http
PGDG 1.6.3
postgresql-13-http
PGDG 1.6.3
u24 x86_64 postgresql-17-http
PGDG 1.6.3
postgresql-16-http
PGDG 1.6.3
postgresql-15-http
PGDG 1.6.3
postgresql-14-http
PGDG 1.6.3
postgresql-13-http
PGDG 1.6.3
u24 aarch64 postgresql-17-http
PGDG 1.6.3
postgresql-16-http
PGDG 1.6.3
postgresql-15-http
PGDG 1.6.3
postgresql-14-http
PGDG 1.6.3
postgresql-13-http
PGDG 1.6.3

扩展安装

使用 pig 命令行工具安装 pg_http 扩展:

pig ext install pg_http; # 扩展名称
pig ext install http; # 标准包名

使用 Pigsty剧本 安装 pg_http 扩展:

./pgsql.yml -t pg_extension -e '{"pg_extensions": ["pg_http"]}' # -l <集群名>

YUM仓库 手工安装 pg_http RPM 包:

dnf install pgsql_http_17*;
dnf install pgsql_http_16*;
dnf install pgsql_http_15*;
dnf install pgsql_http_14*;
dnf install pgsql_http_13*;

APT仓库 手工安装 pg_http DEB 包:

apt install postgresql-17-http;
apt install postgresql-16-http;
apt install postgresql-15-http;
apt install postgresql-14-http;
apt install postgresql-13-http;

使用以下 SQL 命令在已经安装此扩展插件的 PG 集群上 启用 http 扩展:

CREATE EXTENSION http;

使用方法

https://github.com/pramsey/pgsql-http

请求与响应的模式:

     Composite type "public.http_request"
    Column    |       Type        | Modifiers
--------------+-------------------+-----------
 method       | http_method       |
 uri          | character varying |
 headers      | http_header[]     |
 content_type | character varying |
 content      | character varying |

    Composite type "public.http_response"
    Column    |       Type        | Modifiers
--------------+-------------------+-----------
 status       | integer           |
 content_type | character varying |
 headers      | http_header[]     |
 content      | character varying |

例子

Sending HTTP GET requests with SQL

CREATE EXTENSION http;

-- get content
SELECT content FROM http_get('http://httpbun.com/');

-- get status and content_type
SELECT status, content_type FROM http_get('http://httpbun.com/');

--  status |       content_type
-- --------+--------------------------
--     200 | text/html; charset=utf-8

-- get headers
SELECT (unnest(headers)).* FROM http_get('http://httpbun.com/');

--             field           |                      value
--  ---------------------------+--------------------------------------------------
--  Location                  | https://httpbun.com/
--  Date                      | Mon, 04 Nov 2024 09:00:36 GMT
--  Content-Length            | 0
--  Connection                | close
--  alt-svc                   | h3=":443"; ma=2592000
--  content-security-policy   | frame-ancestors 'none'
--  content-type              | text/html
--  date                      | Mon, 04 Nov 2024 09:00:37 GMT
--  strict-transport-security | max-age=31536000; includeSubDomains; preload
--  x-content-type-options    | nosniff
--  x-powered-by              | httpbun/af040d24038613575a85f74c2283ae79f8169927
--  (11 rows)
SELECT status, content::json->'form' AS form FROM http_post('http://httpbun.com/post', jsonb_build_object('myvar','myval','foo','bar'));

Issue http put requests:

SELECT status, content_type, content::json->>'data' AS data
  FROM http_put('http://httpbun.com/put', 'some text', 'text/plain');


--  status |   content_type   |   data
-- --------+------------------+-----------
--  200 | application/json | some text

Issue http post request:





最后修改 2025-03-20: update extension version (52133a3)