Postgres Creating Schema in a specific database
This works, if - and only if - you're using psql:
postgres@berry-pc:~$ psql template1psql (8.4.10)Type "help" for help.template1=# CREATE DATABASE foo;CREATE DATABASEtemplate1=# \connect foo;psql (8.4.10)You are now connected to database "foo".foo=# \connect template1psql (8.4.10)You are now connected to database "template1".template1=# DROP DATABASE foo;DROP DATABASEtemplate1=# \q
\connect
is a psql command. It's not normal SQL, so you can't use that in a .sql file. There is no way to do it from within a sql file, as far as I know. The rationale behind this, is that you should reconnect to a different database once you want to use that different database. This is for database separation. The reason MySQL has implemented the use $database
syntax is because of it's lack of schema's, but PostgreSQL doesn't have a command like that, as a database should be separated in schema's, rather than databases.