The USE command switches the active database; PostgreSQL accomplishes the same task with \c or SET search_path.
USE database_name; tells MariaDB to make a different database the default for subsequent queries, so unqualified table names resolve inside that database.
PostgreSQL doesn’t implement USE. Instead, connect to another database with the meta-command \c
or change your schema search path using SET search_path
.
Run \c
when you must access an entirely different database cluster.Use SET search_path
when you only need tables from another schema inside the same database.
See the Syntax section below for both approaches, including parameters.
Suppose you routinely jump between development and production databases that each contain Customers
, Orders
, Products
, and OrderItems
tables. You can switch with \c
or set a schema path so queries stay concise.
Yes.Grant your role usage on selected schemas, then set search_path
at login for least-privilege access.
Automate environment selection with connection strings rather than ad-hoc USE commands. For multi-schema databases, store SET search_path
in a startup script or application pool settings.
Avoid assuming USE exists in PostgreSQL. Forgetting to adjust search_path
may lead to “relation not found” errors if you omit schema prefixes.
MariaDB’s USE is conceptually split between \c
and SET search_path
in PostgreSQL.Pick the one matching your goal: new database or new schema context.
.
No. \c is a psql client command. Applications should open a new connection to the desired database instead.
Yes. You can set search_path per session, transaction, or even per user in postgresql.conf
.
Negligibly. PostgreSQL resolves schemas during planning; the overhead is minimal compared to query execution time.