postgresql - 如何在 psql 中获取多个函数?

标签 postgresql psql

我有一个包含至少 6 个函数文件的目录。

我正在使用 psql,我需要能够一次获取(初始化?)所有函数文件。

我确定制作一个函数并调用所有其他函数,如 SELECT fn1, fn2 是行不通的。

执行 \i functions_folder/fn1.sql 6 次也不理想。

那么有什么方法可以(也许)\i functions/*.sql?这样做目前给了我

functions/*.sql: 没有那个文件或目录

我在 postgresql 9.6.2 上使用 psql

最佳答案

如果您使用的是 *nix 操作系统:

postgres=# \! cat ./functions/*.sql > all_functions.sql
postgres=# \i all_functions.sql

对于 Windows,尝试找到 cat 的类似物(我记得它是带有一些标志的 copy 命令)

PS 我觉得可以通过使用反引号来完成:

Within an argument, text that is enclosed in backquotes (`) is taken as a command line that is passed to the shell. The output of the command (with any trailing newline removed) replaces the backquoted text.

Documentation

但是还是不知道怎么办。可能更有经验的人会提供提示......

关于postgresql - 如何在 psql 中获取多个函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43816381/

相关文章:

django - Postgresql 即使有索引也慢连接?

regex - 替换 regexp_matches 的内容

python - DatabaseError : current transaction is aborted, 命令在事务 block 结束之前被忽略?

postgresql - 在 PostgreSQL 中更新引用表时如何违反重复键约束(Unique_Violation)?

postgresql - Cloud9 上的 Postgres 数据库设置要求输入 sudo 密码

postgresql - 如何设置 PostgreSQL 教程?

c - PostgreSQL C 函数建议

java - 查询从 2 个时间戳之间的数据库中选择数据,异常 : time_bucket function does not exists?

go - 如何将 exec.Command 的输出通过管道传输到 Golang 中的另一个命令

sql - 在postgres中添加没有密码的用户