Skip to content

Clients don't seem to respect existing search path #2419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zachsa opened this issue Nov 25, 2020 · 2 comments
Closed

Clients don't seem to respect existing search path #2419

zachsa opened this issue Nov 25, 2020 · 2 comments

Comments

@zachsa
Copy link

zachsa commented Nov 25, 2020

Using Postgres 12, I can create a user and set the search path of that user:

create user "${username}" with encrypted password '${password}';
create schema "${schema}" authorization "${username}";
alter user "${username}" set search_path = "${schema},public";
grant usage on schema public to "${username}";
grant select on all tables in schema public to "${username}";

Using a pg Client, I can see that the search path is set correctly:

SHOW search_path;

// returns "<schema>,public"

Running SELECT queries I see that the custom schema IS in the search path. However, when trying to create a table the search path can't be found:

CREATE TABLE test (
     id    integer PRIMARY KEY,
     name   varchar(40)
);

// returns "no schema has been selected to create in"

If I adjust the SQL to specify the search path first, then it works as expected:

SET search_path = "${schema},public";
CREATE TABLE test (
     id    integer PRIMARY KEY,
     name   varchar(40)
);

If I use Postgres via DBeaver with the same client credentials (and just login with the user, without updating the search path), then this works as expected.

I am creating a client like this:

const client = new Client({
    host,
    user,
    database,
    password,
    port,
  })
client.connect()
await client.query(...)
client.end()
@zachsa
Copy link
Author

zachsa commented Nov 25, 2020

Actually, it looks like queries don't use the search_path either if the table is not on the first schema in the search path list.

@zachsa
Copy link
Author

zachsa commented Nov 25, 2020

Apologies.

Changing the alter user statement fixed this

ALTER ROLE "<user name>" SET search_path = "<schema name>", public;

@zachsa zachsa closed this as completed Nov 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant