我想知道是否有可能/如何在另一个.sql文件中包含一个.sql文件,就像在其他编程语言(如C或Java)中一样?
I was wondering if it is possible/how to include one .sql file in another .sql file, as is done in other programming languages like C or Java?
我在问,因为我想将我的sql脚本组织成支持库文件和应用程序脚本,等等。我四处搜索,解决方案似乎是关于从psql客户端加载.sql文件(参见例如 postgreSQL - psql \ i:如何执行给定路径中的脚本)。我感兴趣的是从sql脚本中加载库.sql脚本。
I am asking because I wanted to organize my sql scripts into support library files and application scripts, and so on. I searched around, and solutions seem to be about loading .sql files from the psql client (see e.g. postgreSQL - psql \i : how to execute script in a given path). What I am interested in is to load a library .sql script from inside a sql script.
P.S。我正在使用PL / pgSQL(PostgreSQL 9.3)。
P.S. I am using PL/pgSQL (PostgreSQL 9.3).
推荐答案基于答案可以从SQL脚本中引用另一个SQL文件,在PostgreSQL上,只需使用 \ i 语法。我刚刚测试过并且在PostgreSQL 9.6上运行良好:
Based on the answer It is possible to reference another SQL file from SQL script, on PostgreSQL, you can include another SQL's files just using the \i syntax. I just tested and is working good on PostgreSQL 9.6:
\i other_script.sql SELECT * FROM table_1; SELECT * FROM table_2;更多推荐
如何从PostgreSQL中的sql脚本导入外部sql脚本?
发布评论