Subject: [pgjdbc/pgjdbc] issue #3605: PgConnection.setSchema() does not support multiple schemas

From: "cgm-aw (@cgm-aw)" <[email-masked]>
Date: Tue, 15 Apr 2025 07:36:19 +0000

**Describe the issue**
According to the [documentation](https://jdbc.postgresql.org/documentation/use/#connection-parameters), `currentSchema` can be a comma-separated list of schemas. While this works for the connection string, it does not work for `PgConnection.setSchema()`. 

**Driver Version?** 
Latest

**Java Version?**
Any

**OS Version?**
Any

**PostgreSQL Version?**
Any

**To Reproduce**
Call `PgConnection.setSchema("a, b")` - the search path will be set to the string "a, b" instead to the schemas "a" and "b".

**Expected behaviour**
The search path should be set to a list of schemas if a comma-separated list is provided.

**Comments**
This is because `PgConnection.setSchema()` puts single quotes around the passed schema:
```
StringBuilder sb = new StringBuilder();
sb.append("SET SESSION search_path TO '"); // See here
Utils.escapeLiteral(sb, schema, getStandardConformingStrings());
sb.append("'"); // and here
```
I'm happy to provide a reproducer if you need one, but I think the issue is pretty clear.
There is some escaping going on, a comma-separated list passed a a string ("a, b") should of course be escaped to: 'a', 'b'
I don't know if you have helpful utils to do this, so I didn't create a pull request. If you like, I can try :)

Best regards

Andreas

---

From: "davecramer (@davecramer)" <[email-masked]>
Date: Tue, 15 Apr 2025 12:31:45 +0000

Great find, thanks, and yes a PR would be welcome
Dave

---

From: "cgm-aw (@cgm-aw)" <[email-masked]>
Date: Tue, 15 Apr 2025 14:31:49 +0000

Please check my PR: https://github.com/pgjdbc/pgjdbc/pull/3606

I could not get all tests running, but I'm pretty sure that is not due to my change. I would be glad if a maintainer could run all tests to make sure.
Also please make sure this looks downwards-compatible to you, I tried my best to do so.