http
pg_http : HTTP client for PostgreSQL, allows web page retrieval inside the database.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 4070 | http
|
pg_http
|
1.7.1 |
UTIL
|
MIT
|
C
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d--
|
No
|
Yes
|
No
|
Yes
|
no
|
no
|
| Relationships | |
|---|---|
| See Also | pg_net
pg_curl
pgjwt
pg_smtp_client
gzip
bzip
zstd
pgjq
pgmb
|
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | MIXED
|
1.7.1 |
18
17
16
15
14
|
pg_http |
- |
| RPM | PIGSTY
|
1.7.1 |
18
17
16
15
14
|
pgsql_http_$v |
- |
| DEB | PGDG
|
1.7.1 |
18
17
16
15
14
|
postgresql-$v-http |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
el8.aarch64
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
el9.x86_64
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
el9.aarch64
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
el10.x86_64
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
el10.aarch64
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
PIGSTY 1.7.1
|
d12.x86_64
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
d12.aarch64
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
d13.x86_64
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
d13.aarch64
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
u22.x86_64
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
u22.aarch64
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
u24.x86_64
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
u24.aarch64
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
u26.x86_64
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
u26.aarch64
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
PGDG 1.7.1
|
Source
pig build pkg pg_http; # build rpmInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall this extension with pig:
pig install pg_http; # install via package name, for the active PG version
pig install http; # install by extension name, for the current active PG version
pig install http -v 18; # install for PG 18
pig install http -v 17; # install for PG 17
pig install http -v 16; # install for PG 16
pig install http -v 15; # install for PG 15
pig install http -v 14; # install for PG 14Create this extension with:
CREATE EXTENSION http;Usage
Sources: README, v1.7.1 release
http lets SQL code make HTTP requests through libcurl. Use it for controlled integration points such as triggers that notify an external service, SQL jobs that fetch a small remote payload, or database-side webhook calls.
CREATE EXTENSION http;Request And Response Types
Every request uses http_request and returns http_response:
http_request(method http_method, uri varchar, headers http_header[], content_type varchar, content varchar)
http_response(status integer, content_type varchar, headers http_header[], content varchar)Convenience wrappers call the same underlying http(http_request) function:
http_get(uri varchar)http_get(uri varchar, data jsonb)http_post(uri varchar, content varchar, content_type varchar)http_post(uri varchar, data jsonb)http_put(uri varchar, content varchar, content_type varchar)http_patch(uri varchar, content varchar, content_type varchar)http_delete(uri varchar)http_head(uri varchar)
Examples
SELECT status, content_type, content
FROM http_get('https://httpbun.com/ip');
SELECT content::json->'headers'->>'Authorization'
FROM http((
'GET',
'https://httpbun.com/headers',
http_headers('Authorization', 'Bearer token'),
NULL,
NULL
)::http_request);
SELECT status, content::json->'form' AS form
FROM http_post(
'https://httpbun.com/post',
jsonb_build_object('myvar', 'myval', 'foo', 'bar')
);
SELECT status, content_type, content::json->>'data' AS data
FROM http_put('https://httpbun.com/put', 'some text', 'text/plain');Inspect response headers by unnesting the headers array:
SELECT (unnest(headers)).*
FROM http_get('https://httpbun.com/');Binary Content
The README warns that varchar::bytea is not safe for binary response bodies because it stops at zero-valued bytes. Use text_to_bytea(content) for response content and bytea_to_text(bytea) when sending binary request bodies.
WITH http AS (
SELECT * FROM http_get('https://httpbingo.org/image/png')
)
SELECT content_type, length(text_to_bytea(content)) AS bytes
FROM http;Timeout And Version Notes
pg_http 1.7.1 is a compatibility and documentation release: it adds timeout examples, adds PostgreSQL 17 wait-event hooks, and includes PostgreSQL 19 support fixes. The user-facing SQL API remains the README surface above.