pg_curl

Run curl actions for data transfer in URL syntax

Overview

PIGSTY 3rd Party Extension: pg_curl : Run curl actions for data transfer in URL syntax

Information

Metadata

  • Latest Version: 2.4
  • Postgres Support: 17,16,15,14,13
  • Need Load: Shared library do not need explicit loading
  • Need DDL: Need CREATE EXTENSION DDL
  • Relocatable: Can not install to arbitrary schema
  • Trusted: Untrusted, Require Superuser to Create
  • Schemas: N/A
  • Requires: N/A

RPM / DEB

  • RPM Repo: PIGSTY
  • RPM Name: pg_curl_$v*
  • RPM Ver : 2.4
  • RPM Deps: N/A
  • DEB Repo: PIGSTY
  • DEB Name: postgresql-$v-pg-curl
  • DEB Ver : 2.4
  • DEB Deps: N/A

Packages

OS Arch PG17 PG16 PG15 PG14 PG13
el8 x86_64 pg_curl_17
PIGSTY 2.4
pg_curl_16
PIGSTY 2.4
pg_curl_15
PIGSTY 2.4
pg_curl_14
PIGSTY 2.4
pg_curl_13
PIGSTY 2.4
el8 aarch64 pg_curl_17
PIGSTY 2.4
pg_curl_16
PIGSTY 2.4
pg_curl_15
PIGSTY 2.4
pg_curl_14
PIGSTY 2.4
pg_curl_13
PIGSTY 2.4
el9 x86_64 pg_curl_17
PIGSTY 2.4
pg_curl_16
PIGSTY 2.4
pg_curl_15
PIGSTY 2.4
pg_curl_14
PIGSTY 2.4
pg_curl_13
PIGSTY 2.4
el9 aarch64 pg_curl_17
PIGSTY 2.4
pg_curl_16
PIGSTY 2.4
pg_curl_15
PIGSTY 2.4
pg_curl_14
PIGSTY 2.4
pg_curl_13
PIGSTY 2.4
d12 x86_64 postgresql-17-pg-curl
PIGSTY 2.4
postgresql-16-pg-curl
PIGSTY 2.4
postgresql-15-pg-curl
PIGSTY 2.4
postgresql-14-pg-curl
PIGSTY 2.4
postgresql-13-pg-curl
PIGSTY 2.4
d12 aarch64 postgresql-17-pg-curl
PIGSTY 2.4
postgresql-16-pg-curl
PIGSTY 2.4
postgresql-15-pg-curl
PIGSTY 2.4
postgresql-14-pg-curl
PIGSTY 2.4
postgresql-13-pg-curl
PIGSTY 2.4
u22 x86_64 postgresql-17-pg-curl
PIGSTY 2.4
postgresql-16-pg-curl
PIGSTY 2.4
postgresql-15-pg-curl
PIGSTY 2.4
postgresql-14-pg-curl
PIGSTY 2.4
postgresql-13-pg-curl
PIGSTY 2.4
u22 aarch64 postgresql-17-pg-curl
PIGSTY 2.4
postgresql-16-pg-curl
PIGSTY 2.4
postgresql-15-pg-curl
PIGSTY 2.4
postgresql-14-pg-curl
PIGSTY 2.4
postgresql-13-pg-curl
PIGSTY 2.4
u24 x86_64 postgresql-17-pg-curl
PIGSTY 2.4
postgresql-16-pg-curl
PIGSTY 2.4
postgresql-15-pg-curl
PIGSTY 2.4
postgresql-14-pg-curl
PIGSTY 2.4
postgresql-13-pg-curl
PIGSTY 2.4
u24 aarch64 postgresql-17-pg-curl
PIGSTY 2.4
postgresql-16-pg-curl
PIGSTY 2.4
postgresql-15-pg-curl
PIGSTY 2.4
postgresql-14-pg-curl
PIGSTY 2.4
postgresql-13-pg-curl
PIGSTY 2.4

Installation

Install pg_curl via the pig CLI tool:

pig ext install pg_curl

Install pg_curl via Pigsty playbook:

./pgsql.yml -t pg_extension -e '{"pg_extensions": ["pg_curl"]}' # -l <cls>

Install pg_curl RPM from YUM repo directly:

dnf install pg_curl_17*;
dnf install pg_curl_16*;
dnf install pg_curl_15*;
dnf install pg_curl_14*;
dnf install pg_curl_13*;

Install pg_curl DEB from APT repo directly:

apt install postgresql-17-pg-curl;
apt install postgresql-16-pg-curl;
apt install postgresql-15-pg-curl;
apt install postgresql-14-pg-curl;
apt install postgresql-13-pg-curl;

Enable pg_curl extension on PostgreSQL cluster:

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 2025-02-17: add extension part (cfa504b)