Alessandro Scotti
Alessandro Scotti

Reputation: 21

Is it possible to set postgres search_path in node-postgres?

I'm moving an application from RoR to Express.js. ActiveRecord postgres adapter has the search_path configuration option.

Is it possible to set the search_path for the Client ?

Upvotes: 2

Views: 3689

Answers (3)

unused-user
unused-user

Reputation: 1

process.env.PGOPTIONS="-c search_path=some_schema"

Upvotes: 0

Tim Kozak
Tim Kozak

Reputation: 4182

Yes sure you can automaticaly triger SET command "on" connection event

pool.on('connect', (client) => {
  client.query('SET search_path TO schema,public');
});

Upvotes: 2

Chris Travers
Chris Travers

Reputation: 26464

My preference would be to chance this on the database or user if possible.

ALTER [DATABASE or USER] [name] set search_path='[searchpath]'

If that fails you can always make sure your search path is set by building into your connection logic:

SET search_path='[searchpath]'

That will set it on the connection.

Upvotes: 2

Related Questions