【问题标题】:Run .sql within .sh file under the search path在搜索路径下的 .sh 文件中运行 .sql
【发布时间】:2021-09-09 15:34:27
【问题描述】:

目前.sh文件中的搜索路径设置为:

export PSQL_PREAMBLE='SET search_path TO public,mimiciii'

我正在跑步:

{ echo "${PSQL_PREAMBLE}; DROP TABLE IF EXISTS ventilation_durations; CREATE TABLE ventilation_durations AS "; cat durations/ventilation_durations.sql; } | sed -r -e "${REGEX_DATETIME_DIFF}" | sed -r -e "${REGEX_SCHEMA}" | psql ${CONNSTR}

问题:在.sh 文件中运行上面的代码后,我上面运行的代码似乎没有捕捉到 PSQL_PREAMBLE 中设置的搜索路径。它只是没有捕获我在 mimiciii 架构中创建的函数

(完整的脚本在这里:https://github.com/MIT-LCP/mimic-code/blob/main/mimic-iii/concepts/postgres_make_concepts.sh

【问题讨论】:

    标签: linux postgresql shell


    【解决方案1】:

    这应该可以正常工作,但它似乎不必要地复杂。

    快跑

    export PGOPTIONS=-csearch_path=public,mimiciii
    

    在脚本的开头,search_path 将自动设置为以后的所有 psql 调用。

    请参阅PGOPTIONSoptions 连接参数和-c option of postgres 的文档。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-02
      • 1970-01-01
      • 2013-08-08
      • 1970-01-01
      相关资源
      最近更新 更多