According to the PostgreSQL documentation, there appears to be support for SET CONNECTION.

However, when I try to execute it from the psql prompt, I get

ERROR: unrecognized configuration parameter "connection"

I'm well aware of using \connect but I want to be able to switch databases within the execution of a .sql file.

Is this a bug in PostgreSQL? Or does some flag need to be set to create the parameter?


1 Answer 1


Converting question comments into an answer


It seems that you missed a section of the documentation: Chapter 34. ECPG - Embedded SQL in C. The PostgreSQL documentation is not ideal (but IMO it is much better then many others). Hint: to avoid inconveniences look at the page name in the address, for example plpgsql-declarations.html is about DECLARE variables in the plpgsql blocks and sql-declare.html is about DECLARE cursors in the pure SQL.


If using psql, you still can make use of \c - especially if it does not require typing a password.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.