Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create database, tables etc in one script postgresql

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?

like image 759
Ariel Grabijas Avatar asked Nov 25 '12 16:11

Ariel Grabijas


People also ask

Can we create multiple databases in PostgreSQL?

A single Postgres server process can manage multiple databases at the same time. Each database is stored as a separate set of files in its own directory within the server's data directory. To view all of the defined databases on the server you can use the \list meta-command or its shortcut \l .


1 Answers

Replace the T-SQL batch terminator GO with the PostgreSQL batch terminator ;.
GO is not supported in postgreSQL

  • Microsoft SQL Server to PostgreSQL Migration by Ian Harding

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

 CREATE DATABASE testdatabase; 
 \c testdatabase 
 CREATE TABLE testtable (testcolumn int); 
  • PostgreSQL for MySQL users
like image 200
John Woo Avatar answered Oct 02 '22 15:10

John Woo