RE: postgresql and dynamically changing the schema per query

1,693 views
Skip to first unread message

S Ahmed

unread,
Mar 10, 2014, 2:44:23 PM3/10/14
to golan...@googlegroups.com
Hello

I want to build a golang based service that will connect to 1 or more postgresql database servers.

For multi-tenancy, I need to separate clients into their own schema.

Is there a way for me to dynamically change the schema on a per query basis with any of the existing libraries?

Robert Johnstone

unread,
Mar 10, 2014, 3:26:43 PM3/10/14
to golan...@googlegroups.com
Hello,

I'm not an expert with PostgreSQL, but you should be able to handle changes to the schema with any library that provides support for passing raw SQL queries to the database.  See, for example, section 5.7.3 in the documentation.  I suspect nearly any package listed on godoc.org should handle this.

palaniappan meiyappan

unread,
Jun 23, 2014, 3:44:03 PM6/23/14
to golan...@googlegroups.com
Hi,

I have a similar issue.
Can you please post the solution if any?
Thanks.

Rodrigo Kochenburger

unread,
Jun 23, 2014, 3:52:22 PM6/23/14
to palaniappan meiyappan, golan...@googlegroups.com
You can change the schema search path for that specific session/connection[1].

i.e. db.Exec("SET search_path TO myschema")

I'm not sure how this will play w/ database/sql's connection pooling because the setting is per connection, so that might not work.

Might be just easier to provide each client with their own database, instead of just schemas, which is also probably a good idea anyway.


- RK


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages