Change default schema for user
Asked Answered
O

2

20
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?

Overlooker answered 8/6, 2017 at 7:22 Comment(0)
T
30

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

Tautologism answered 8/6, 2017 at 7:27 Comment(1)
On the linked documentation page, I don't see any reference to alter role set search_path to The "exact" syntax is needed, because the grant seems to execute, but the default schema is not changed.Hermes
K
6

In PostGres the exact command would be

ALTER USER 'your-user' set SEARCH_PATH = 'schema_name';
Keheley answered 6/9, 2022 at 15:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.