PIGSTY

pg_curl

Run curl actions for data transfer in URL syntax

Overview

Attributes

YesNoYesNoYesYesNo-

Packages

EL
PIGSTY
pg_curl_$v*2.4-
17
16
15
14
13
Debian
PIGSTY
postgresql-$v-pg-curl2.4-
17
16
15
14
13

Availability

PG17PG16PG15PG14PG13
el8.x86_64
2.4.3
2.4.3
2.4.3
2.4.3
2.4.3
el8.aarch64
2.4.3
2.4.3
2.4.3
2.4.3
2.4.3
el9.x86_64
2.4.3
2.4.3
2.4.3
2.4.3
2.4.3
el9.aarch64
2.4.3
2.4.3
2.4.3
2.4.3
2.4.3
d12.x86_64
2.4
2.4
2.4
2.4
2.4
d12.aarch64
2.4
2.4
2.4
2.4
2.4
u22.x86_64
2.4
2.4
2.4
2.4
2.4
u22.aarch64
2.4
2.4
2.4
2.4
2.4
u24.x86_64
2.4
2.4
2.4
2.4
2.4
u24.aarch64
2.4
2.4
2.4
2.4
2.4
CONTRIB
PGDG
PIGSTY

Download

To add the required PGDG / PIGSTY upstream repository, use:

pig repo add pgdg -u    # add PGDG repo and update cache (leave existing repos)
pig repo add pigsty -u  # add PIGSTY repo and update cache (leave existing repos)
pig repo add pgsql -u   # add PGDG + Pigsty repo and update cache (leave existing repos)
pig repo set all -u     # set repo to all = NODE + PGSQL + INFRA  (remove existing repos)
./node.yml -t node_repo -e node_repo_modules=node,pgsql # -l <cluster>

Or download the latest packages directly:


Install

Install this extension with:

pig ext install pg_curl; # install by extension name, for the current active PG version

pig ext install pg_curl -v 17;   # install for PG 17
pig ext install pg_curl -v 16;   # install for PG 16
pig ext install pg_curl -v 15;   # install for PG 15
pig ext install pg_curl -v 14;   # install for PG 14
pig ext install pg_curl -v 13;   # install for PG 13
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*;
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;
./pgsql.yml -t pg_ext -e '{"pg_extensions": ["pg_curl"]}' # -l <cls>

Create this extension with:

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$;