在一个脚本 postgresql 中创建数据库、表等

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13552773/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 00:34:32  来源:igfitidea点击:

Create database, tables etc in one script postgresql

sqlpostgresqlpostgresql-9.1

提问by Ariel Grabijas

I've a script:

我有一个脚本:

CREATE DATABASE ahop

GO

CREATE TABLE shop.dbo.TABLE1 ( 
); 

CREATE TABLE shop.dbo.TABLEN ( 
); 

But it doesn't seem to work in PostgreSQL. Error message: "error near GO". I dont get it, how to create scripts in Postgresql?

但它似乎在 PostgreSQL 中不起作用。错误消息:“GO 附近的错误”。我不明白,如何在 Postgresql 中创建脚本?

回答by John Woo

Replace the T-SQL batch terminator GOwith the PostgreSQL batch terminator ;.
GOis not supported in postgreSQL

将 T-SQL 批处理终止符GO替换为 PostgreSQL 批处理终止符;
GOpostgreSQL 不支持

you need to connect on the database using \. eg,

您需要使用\. 例如,

 CREATE DATABASE testdatabase; 
 \c testdatabase 
 CREATE TABLE testtable (testcolumn int);