如何从PostgreSQL中的sql脚本导入外部sql脚本?

编程入门 行业动态 更新时间:2024-10-26 16:27:48
本文介绍了如何从PostgreSQL中的sql脚本导入外部sql脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想知道是否有可能/如何在另一个.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脚本?

本文发布于:2023-10-28 13:18:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1536742.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   PostgreSQL   sql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!