首页 > 解决方案 > plpython3u Docker Postgres 安装 3rd

问题描述

我有点迷失如何在 plpython3u 存储过程中使用 python 库。我有下面的泊坞窗文件。我可以使用 plpython3u,但在存储的 plpython3u 过程中编写以下语句失败:

导入请求

我想我必须告诉 plpython3u 第 3 方库的安装位置,因为我不知道该怎么做。

下面列出的是我的 docker 文件的副本

FROM postgres:13.2
RUN apt-get update && apt-get install -y  postgresql-13-mysql-fdw && apt-get install -y postgresql-plpython3-13 && apt-get -y install python3-pip
RUN pip3 install requests

这是我的存储过程的示例

CREATE OR REPLACE FUNCTION client_billing.process_sync_date(in_sync_date_id bigint) RETURNS void AS
$BODY$
    import requests
    try:
        response = requests.get("http://www.google.com")
        plpy.debug(response)
    except requests.exceptions.RequestException as e:  # This is the correct syntax
        plpy.debug(requesterror.RequestError(e))
$BODY$
  LANGUAGE plpython3u VOLATILE
  COST 100;
ALTER FUNCTION client_billing.process_sync_date(in_sync_date_id bigint) OWNER TO postgres;

注意我回到 pgadmin 如下:

ERROR:  ModuleNotFoundError: No module named 'requests'
CONTEXT:  Traceback (most recent call last):
  PL/Python function "process_sync_date", line 2, in <module>
    import requests
PL/Python function "process_sync_date"
SQL state: 38000

标签: pythonpostgresqldocker

解决方案


推荐阅读