Historically, I have not worked with Postgres much. So, when I had to start using it, one of my first questions was how to create a schema, and how to use it for my new tables and such.
Creating a schema is exactly what you expect:
create schema myschema;
But using it is not quite what I expected. Of course, you can do the standard thing when you’re managing your objects and use . like this:
create table myschema.mytable (x int);
But what if you just want:
create table mytable (x int);
to go into myschema by default? To do this in Postgres, you have to add the schema to your search path. By default your search path will be just set to the public schema; you can view it like this:
You can set it to one or more schemas in reality. The first schema your query sees a the named table in will be the one it takes it from. The first schema in the list will be the default one for when you create new objects too. So, if you did this:
SET search_path TO myschema; create table mytable (x int);
Then your table would in fact be created in the “myschema” schema properly.