====== PostgreSQL HTTP Client ======
* [[https://github.com/pramsey/pgsql-http]]
* [[https://anthonysotolongo.wordpress.com/2017/05/08/peticiones-http-desde-postgresql/]]
* [[https://docs.tantorlabs.ru/tdb/en/16_11/se/pgsql-http.html]]
* [[https://www.postgresonline.com/journal/archives/371-http-extension.html]]
Esta extensión permite hacer peticiones http a una URL como XmlHTTPRequest como en SQL SERVER
===== Instalación =====
* [[https://share.google/aimode/kz4Fp00zxauMDv5me]]
Instalación en Debian:
#Instalar dependencias:
sudo apt install curl ca-certificates postgresql-common -y
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
#Actualizar APT
sudo apt update
#Instalar la extension en postgresql, cambiar 15 por la versión que se tiene de postgresql (ver version: pgsql --version )
sudo apt install postgresql-15-http
En PostgreSQL
#Habilitar la extensión por Base de Datos en PostgreSQL
# ingresar a PSQL
# Seleccionar la DB
\c
#Habilitar extensión:
CREATE EXTENSION http;
===== USO =====
* http_header(field VARCHAR, value VARCHAR) returns http_header
* http(request http_request) returns http_response
* http_get(uri VARCHAR) returns http_response
* http_post(uri VARCHAR, content VARCHAR, content_type VARCHAR) returns http_response
* http_put(uri VARCHAR, content VARCHAR, content_type VARCHAR) returns http_response
* http_delete(uri VARCHAR) returns http_resonse, urlencode(string VARCHAR) returns text
Ejemplo de uso:
#Ejemplo 1:
SELECT content FROM http_get('http://httpbun.com/ip');
#Ejemplo 2:
SELECT h.content, h.content_type, hkv.value As dt
FROM http_get('http://postgis.net/tips/') AS h
LEFT JOIN LATERAL (
SELECT * FROM unnest(h.headers) WHERE field = 'Date'
) AS hkv ON true;
==== Manejando las Respuestas JSON ====
* [[https://gitlab.syncad.com/hive/pgsql-http/-/blob/master/sql/http.sql]]
* [[https://share.google/aimode/XSC0ImCd1M7NKp77z]]
* [[https://stackoverflow.com/questions/39224382/how-can-i-import-a-json-file-into-postgresql]]
* [[https://h3manth.com/scribe/http-request-postgres/]]
* [[https://pgxn.org/dist/http/]]
* [[https://docs.tantorlabs.ru/tdb/en/15_15/certified/pgsql-http.html]]
* [[https://medium.com/@interviewbuddies/how-to-read-json-data-in-postgresql-2fe5f8565218]]
Permisos:
* [[https://www.answeroverflow.com/m/1397749087289348097]]