Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change default schema for user

create schema bla;

-- then create table table_name into this schema

Then I want change default schema for user (user is postgres)

I do: ALTER ROLE postgres SET search_path TO bla; (Query returned successfully with no result).

When I try SELECT * FROM table_name gives error relation "table_name" does not exist

Though SELECT * FROM bla.table_name works fine.

What is wrong in my attempt to change default schema for user?

like image 780
Oto Shavadze Avatar asked Jun 08 '17 07:06

Oto Shavadze


People also ask

How do I change the default schema for a SQL Server user?

In order to set the default schema for a Windows Group, open SQL Server Management Studio, navigate to Security > Logins, right click on the Windows Group that you want to change and choose Properties.

How do I change the default database schema?

In the Database Administration view upper pane, select the database. Right-click the database and select Set default schema. The Set default schema dialog appears.

How do I find the default schema for a user in SQL Server?

How can you tell the name of the current default schema? SELECT SCHEMA_NAME(); The SCHEMA_NAME() function will return the name of a schema if you pass it the schema_id but if you don't pass anything, it will return the name of the current default schema.

How do I change the default schema in postgresql?

SET search_path TO inventory, public; Now inventory is a default schema and you don't need to mention it explicitly to access it. You can change the name or the ownership of a schema by using ALTER SCHEMA. DROP SCHEMA [IF EXISTS] schema_name [CASCADE | RESTRICT];


1 Answers

I think you need to relogin for that. With ALTER USER ... SET you change

Session defaults for run-time configuration variables

Also from ALTER ROLE SET manual:

Role-specific variable settings take effect only at login;

But don't apply changes to current session. If you want immediate change use:

SET search_path TO bla;

It will change path on session level

like image 68
Vao Tsun Avatar answered Sep 27 '22 21:09

Vao Tsun