[英]Load SQL file into postgresql function
i'd like to load a local file and execute it in postgresql function but i dont know how..我想加载一个本地文件并在 postgresql function 中执行它,但我不知道如何..
i got a table which has only 1 column contains absolute file path like↓我有一个表,它只有 1 列包含绝对文件路径,如↓
tmp_import_files.filename
-----------------
/tmp/test_file.sql
/tmp/test_file1.sql
/tmp/test_file2.sql
-----------------
and want to make function something like this..并想让 function 像这样..
FOR rec IN SELECT filename FROM tmp_import_files ORDER BY filename ASC LOOP
RAISE NOTICE rec.filename
FOR sql IN LOAD rec.filename LOOP -- LOAD is not right?
EXECUTE sql;
END LOOP;
END LOOP;
LOAD allows to load shared library code in the PostgreSQL executable: it does not allow to load SQL files. LOAD 允许在 PostgreSQL 可执行文件中加载共享库代码:它不允许加载 SQL 文件。
To load and execute SQL files you could try to use psql \i command or system function pg_read_file (see https://www.postgresql.org/docs/12/functions-admin.html#FUNCTIONS-ADMIN-GENFILE ) with more code. To load and execute SQL files you could try to use psql \i command or system function pg_read_file (see https://www.postgresql.org/docs/12/functions-admin.html#FUNCTIONS-ADMIN-GENFILE ) with more code .
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.