I got one suggestion form stackoverflow.com to create schema in a specific database as follows:
CREATE DATABASE foo;
\connect foo;
CREATE SCHEMA yourschema;
But I am getting error as follows:
ERROR: syntax error at or near “\” LINE 2: \connect foo;
^*** Error ***
ERROR: syntax error at or near “\”
Situation :
Login as postgress
create user u1
create database db1 with owner u1
\connect u1
create schema s1
Please help me in creating schema in a specific db.
This works, if – and only if – you’re using psql:
\connectis 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 theuse $databasesyntax 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.