This section describes how to open, close, and switch database connections.
One connects to a database using the following statement:
EXEC SQL CONNECT TOtarget[ASconnection-name] [USERuser-name];
The target can be specified in the following ways:
dbname[@hostname][:port]tcp:postgresql://hostname[:port][/dbname][?options]unix:postgresql://localhost[:port][/dbname][?options]DEFAULTThe connection target DEFAULT initiates a connection to the default database under the default user name. No separate user name or connection name can be specified in that case.
If you specify the connection target directly (that is, not as a string literal or variable reference), then the components of the target are passed through normal SQL parsing; this means that, for example, the hostname must look like one or more SQL identifiers separated by dots, and those identifiers will be case-folded unless double-quoted. Values of any options must be SQL identifiers, integers, or variable references. Of course, you can put nearly anything into an SQL identifier by double-quoting it. In practice, it is probably less error-prone to use a (single-quoted) string literal or a variable reference than to write the connection target directly.
There are also different ways to specify the user name:
usernameusername/passwordusername IDENTIFIED BY passwordusername USING passwordAs above, the parameters username and password can be an SQL identifier, an SQL string literal, or a reference to a character variable.
If the connection target includes any options, those consist of specifications separated by ampersands (keyword=value&). The allowed key words are the same ones recognized by libpq (see Section 34.1.2). Spaces are ignored before any