In PostgreSQL, you can use the \connect meta-command of the client tool psql:
\connect DBNAME
or in short:
\c DBNAME
Note that it is not possible to switch the current database via an SQL command, like you asked.
MySQL's USE DatabaseName is named somewhat confusingly, because what MySQL calls a "database" is more similar to what other systems (like Oracle or PostgreSQL) call a "schema" (and PostgreSQL also lets you access multiple schemas from a single SQL session). To quote the official documentation:
Answer from Will Hartung on Stack OverflowUsers coming from an Oracle Database background may find that the MySQL meaning of a database is closer to what Oracle Database calls a schema.
In PostgreSQL, you can use the \connect meta-command of the client tool psql:
\connect DBNAME
or in short:
\c DBNAME
Note that it is not possible to switch the current database via an SQL command, like you asked.
MySQL's USE DatabaseName is named somewhat confusingly, because what MySQL calls a "database" is more similar to what other systems (like Oracle or PostgreSQL) call a "schema" (and PostgreSQL also lets you access multiple schemas from a single SQL session). To quote the official documentation:
Users coming from an Oracle Database background may find that the MySQL meaning of a database is closer to what Oracle Database calls a schema.
You can connect to a database with \c <database> or \connect <database>.
const client = new Client({database: 'postgres'});
await client.connect();
await client.query('CREATE DATABASE tester;');
await client.query("CREATE ROLE test_role WITH PASSWORD 'password' IN ROLE other_role LOGIN;");
await client.query('CREATE SCHEMA schemes AUTHORIZATION test_role;');
I'm trying to programmatically spin up a new testing database. Im working towards building experience with docker, and incorporating migrations, and as the code is currently written, I start up a client. create a db, user, and schema, then insert a bunch of tables. My issue is that I login to "postgres" DB, and the schema is created in "postgres" but I want it created in the new DB "tester". Besides logging out and back in, is there a way to programmatically switch databases, or create the schema in a database that user isn't currently logged into?
This is javascript, node, porsager/pg
I know that it is possible since I changed the default database in the past but I forgot how I did. There is a file where one can change that, I think.
When you open the psql shell you have to type your own server, database, port etc or accept the default values by entering. And there is a way how to change these default values.
Can anybody help me please? :)
Thank you!