0

I want to create a schema in postgresql with a sql file. I use USE db_name in MySQL After I created the database. Like this:

DROP SCHEMA IF EXISTS db_name;
CREATE SCHEMA db_name;
USE db_name;

And After that I create the tables and tables are created in that database I'm using now. How could I do something like that in postgresql?

0

1 Answer 1

1

Instead of “connecting” to a schema, in PostgreSQL you set the search path. The search path serves two purposes:

  • When accessing an unqualified database object (an object reference without an explicit schema qualification in the shape schema.object), it determines the order in which the schemas are searched for an object of that name.

  • When creating an unqualified database object, the first schema on the search path on which the user has the CREATE privilege is used.

So in PostgreSQL you would use

SET search_path=db_name;

to set the schema where unqualified database objects will be created.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.