postgreSQL-psql \i:如何在给定路径中执行脚本 [英] postgreSQL - psql \i : how to execute script in a given path

查看:593
本文介绍了postgreSQL-psql \i:如何在给定路径中执行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PostgreSQL的新手,我有一个简单的问题:

I'm new to postgreSQL and I have a simple question:

我正在尝试创建一个简单的脚本来创建数据库,因此以后可以调用它像这样:

I'm trying to create a simple script that creates a DB so I can later call it like this:

psql -f createDB.sql

我希望脚本调用其他脚本(用于创建表,添加约束,函数等的单独脚本),例如:

I want the script to call other scripts (separate ones for creating tables, adding constraints, functions etc), like this:

\i script1.sql
\i script2.sql

只要createDB.sql位于相同的目录中,它就可以正常工作。

It works fine provided that createDB.sql is in the same dir.

但是如果我将script2移到目录中在带有createDB的目录下,并修改createDB,使其如下所示:

But if I move script2 to a directory under the one with createDB, and modify the createDB so it looks like this:

\i script1.sql
\i somedir\script2.sql

我得到一个错误:


psql:createDB.sql:2:somedir:权限被拒绝

psql:createDB.sql:2: somedir: Permission denied

我在Windows上使用Postgres Plus 8.3(默认的postgres用户)。

I'm using Postgres Plus 8.3 for windows, default postgres user.

编辑:

对不起,unix斜杠解决了问题。

Silly me, unix slashes solved the problem.

推荐答案

Postgres在Linux / Unix上启动。我怀疑可以通过修复来反斜杠。

Postgres started on Linux/Unix. I suspect that reversing the slash with fix it.

\i somedir/script2.sql 

如果您需要完全符合条件的话

If you need to fully qualify something

\i c:/somedir/script2.sql

如果这不能解决问题,我的下一个猜测是您需要转义反斜杠。

If that doesn't fix it, my next guess would be you need to escape the backslash.

\i somedir\\script2.sql

这篇关于postgreSQL-psql \i:如何在给定路径中执行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆