15

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?

3
  • 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. Commented Nov 25, 2012 at 16:12
  • You also can't specify a table with database.schema.tablename. But this all documented in the manual. Commented Nov 25, 2012 at 16:18
  • the one you showed is for TSQL Commented Nov 25, 2012 at 16:19

1 Answer 1

23

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); 
Sign up to request clarification or add additional context in comments.

2 Comments

Please take a look on my comment to main post.
Is it actually possible to do this without using the psql program?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.