首页 > 解决方案 > Postgres psql \i 似乎添加了一个分号

问题描述

我正在使用 postgres 教授 SQL 课程。我的一个学生发现了一些我不明白的东西。

\i学生正在使用命令(即\i /temp/query.txt:)将 ascii 文件中的多个查询提交给 psql

一些学生在最后一个命令后省略了分号 - 但他们仍然从文件中获得了有效的输出。

IEpsql的行为是在文件末尾附加分号。

Postgres 是否接受分号或 EOF 作为命令的结尾 - 还是这里发生了其他事情?

(我在 Windows 上见过这个。还没有在 Unix 下看过) Postgres V 13.2

标签: postgresqlpsqleof

解决方案


从来源src/bin/psql/mainloop.c

/*
 * If we have a non-semicolon-terminated query at the end of file, we
 * process it unless the input source is interactive --- in that case it
 * seems better to go ahead and quit.  Also skip if this is an error exit.
 */

推荐阅读