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>.
Videos
Please note the following commands:
\listor\l: list all databases\c <db name>: connect to a certain database\dt: list all tables in the current database using yoursearch_path\dt *.: list all tables in the current database regardless yoursearch_path
You will never see tables in other databases, these tables aren't visible. You have to connect to the correct database to see its tables (and other objects).
To switch databases:
\connect database_name or \c database_name
See the manual about psql.
This lists databases:
SELECT datname FROM pg_database
WHERE datistemplate = false;
This lists tables in the current database
SELECT table_schema,table_name
FROM information_schema.tables
ORDER BY table_schema,table_name;