Create a database and make it "current" I have an sql-script that recreates my unit-testing database. At the moment it's run with \i &lt;path_to_my_script&gt;. It goes like

// create user, give him some priveleges

CREATE DATABASE my_database;

CREATE TABLE my_table (
  id UUID primary key,
  data json
);


But my_table is created in postgres database, not in my_database. 

How can I specify that my_table should be created in my_database?



I use postgresql 10.5.
In 'psql', you can change the database you are connected to by using the \c metacommand.  So it would look like this:

CREATE DATABASE my_database;
\c my_database
CREATE TABLE my_table (
  id UUID primary key,
  data json
);


This works from '\i' included files.  When the \i file is done, you will be left in the new database unless you do something to change back to the old one.