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

How to source multiple functions in psql?

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

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

我确定创建一个函数并像 SELECT fn1, fn2 那样调用所有其他函数是行不通的。

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

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

functions/*.sql: No such file or directory

我在 postgresql 9.6.2 上使用 psql

创建一个包含 \i 命令的包装器,以及 \i 包装器。

如果您使用的是 *nix OS:

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

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