pg_curl

Run curl actions for data transfer in URL syntax

Overview

PackageVersionCategoryLicenseLanguage
pg_curl2.4.5UTILMITC
IDExtensionBinLibLoadCreateTrustRelocSchema
4090pg_curlNoYesNoYesNoYes-
Relatedhttp pg_net pgjwt gzip bzip zstd pgjq pg_smtp_client

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY2.4.51817161514pg_curl-
RPMPIGSTY2.4.51817161514pg_curl_$v-
DEBPIGSTY2.4.51817161514postgresql-$v-pg-curl-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
PIGSTY 2.4.5
PIGSTY 2.4.5
PIGSTY 2.4.5
PIGSTY 2.4.5
PIGSTY 2.4.5
u22.x86_64
u22.aarch64
PIGSTY 2.4.5
PIGSTY 2.4.5
PIGSTY 2.4.5
PIGSTY 2.4.5
PIGSTY 2.4.5
u24.x86_64
u24.aarch64
PIGSTY 2.4.5
PIGSTY 2.4.5
PIGSTY 2.4.5
PIGSTY 2.4.5
PIGSTY 2.4.5

Build

You can build the RPM / DEB packages for pg_curl using pig build:

pig build pkg pg_curl         # build RPM / DEB packages

Install

You can install pg_curl directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

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

Install the extension using pig or apt/yum/dnf:

pig install pg_curl;          # Install for current active PG version
pig ext install -y pg_curl -v 18  # PG 18
pig ext install -y pg_curl -v 17  # PG 17
pig ext install -y pg_curl -v 16  # PG 16
pig ext install -y pg_curl -v 15  # PG 15
pig ext install -y pg_curl -v 14  # PG 14
dnf install -y pg_curl_18       # PG 18
dnf install -y pg_curl_17       # PG 17
dnf install -y pg_curl_16       # PG 16
dnf install -y pg_curl_15       # PG 15
dnf install -y pg_curl_14       # PG 14
apt install -y postgresql-18-pg-curl   # PG 18
apt install -y postgresql-17-pg-curl   # PG 17
apt install -y postgresql-16-pg-curl   # PG 16
apt install -y postgresql-15-pg-curl   # PG 15
apt install -y postgresql-14-pg-curl   # PG 14

Create Extension:

CREATE EXTENSION pg_curl;

Usage

CREATE EXTENSION pg_curl;

Perform HTTP Get:

-- wrap curl http get
CREATE OR REPLACE FUNCTION get(url TEXT) RETURNS TEXT LANGUAGE SQL AS $BODY$
WITH s AS (SELECT
               curl_easy_reset(),
               curl_easy_setopt_url(url),
               curl_easy_perform(),
               curl_easy_getinfo_data_in()
) SELECT convert_from(curl_easy_getinfo_data_in, 'utf-8') FROM s;
$BODY$;


SELECT get('https://www.postgresql.org/');

Perform Email SMTP:

CREATE OR REPLACE FUNCTION email(url TEXT, username TEXT, password TEXT, subject TEXT, sender TEXT, recipient TEXT, body TEXT, type TEXT) RETURNS TEXT LANGUAGE SQL AS $BODY$
    WITH s AS (SELECT
        curl_easy_reset(),
        curl_easy_setopt_mail_from(sender),
        curl_easy_setopt_password(password),
        curl_easy_setopt_url(url),
        curl_easy_setopt_username(username),
        curl_header_append('From', sender),
        curl_header_append('Subject', subject),
        curl_header_append('To', recipient),
        curl_mime_data(body, type:=type),
        curl_recipient_append(recipient),
        curl_easy_perform(),
        curl_easy_getinfo_header_in()
    ) SELECT curl_easy_getinfo_header_in FROM s;
$BODY$;

Perform FTP download:

CREATE OR REPLACE FUNCTION download(url TEXT, username TEXT, password TEXT) RETURNS BYTEA LANGUAGE SQL AS $BODY$
    WITH s AS (SELECT
        curl_easy_reset(),
        curl_easy_setopt_password(password),
        curl_easy_setopt_url(url),
        curl_easy_setopt_username(username),
        curl_easy_perform(),
        curl_easy_getinfo_data_in()
    ) SELECT curl_easy_getinfo_data_in FROM s;
$BODY$;

Last Modified 2026-03-12: add pg extension catalog (95749bf)