postgres:如何在.sql文件中执行脚本

one*_*ser -2 postgresql

在SQLite中你可以做到

sqlite3 i.db < x.sql
Run Code Online (Sandbox Code Playgroud)

where x.sql是一个create table语句,i.db是数据库

PostgreSQL中的等价物是什么?

a_h*_*ame 5

Postgres的默认命令行工具是psql它支持命令行参数来指定数据库和脚本名称:

psql -d db_name -f x.sql
Run Code Online (Sandbox Code Playgroud)

有关详细信息(例如,如何指定要用于连接的数据库用户),请参阅手册:https://www.postgresql.org/docs/current/static/app-psql.html