14

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?

Andriy M
  • 76,112
  • 17
  • 94
  • 154
Ariel Grabijas
  • 1,472
  • 5
  • 25
  • 45
  • When i remove "GO" and replace it by ";" I've got an error. Message: "CREATE DATABASE cannot be executed from a function or multi-command string". And the issue is, that i need to execute them all from one script. – Ariel Grabijas Nov 25 '12 at 16:12
  • You also can't specify a table with `database.schema.tablename`. But this all documented in the manual. –  Nov 25 '12 at 16:18
  • the one you showed is for `TSQL` – John Woo Nov 25 '12 at 16:19

1 Answers1

21

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

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

 CREATE DATABASE testdatabase; 
 \c testdatabase 
 CREATE TABLE testtable (testcolumn int); 
John Woo
  • 258,903
  • 69
  • 498
  • 492