database_doc: pq_connect

Next: pq_close, Up: Connection functions [Index]

#### 7.2.1 Connecting to a Postgresql database

Function File: connection = pq_connect (settings)

  Establishes a connection to a postgresql server according to settings and returns an `octave_pq_connection` object connection which can be passed to other functions of the package. There can be multiple connections. An `octave_pq_connection` object contains information on a connection and will be internally altered by the packages functions even though it is only passed as an argument, i.e. Octaves ’pass by value’ semantics are not adhered to in this case.

  settings can be set by `setdbopts` (copied from Octaves `optimset`) and can contain (defaults depend on Postgresql): `host` (hostname), `hostaddr` (numeric host address), `port` (port to connect to), `dbname` (database to connect to), `user` (user name to connect as), `password`, `connect_timeout`, `options` (command-line options to send to the server at run-time, see Postgresql documentation), `sslmode` (`disable`, `allow`, `prefer`, `require`, `verify-ca`, or `verify-full`; see Postgresql documentation of SSL support), `sslcert` (file name of client SSL certificate), `sslkey` (location of secret key for client certificate, file name or external OpenSSL engine (colon-separated engine name and an engine-specific key identifier)), `sslrootcert` (file name of root SSL certificate), `sslcrl` (file name of SSL certificate revocation list), `krbsrvname` (kerberos service name), `service` (service name in pq_service.conf to use for additional parameters).

  All these settings are passed to the server as they are, so it may be better to consult the postgresql documentation for them, e.g. the documentation of the PQconnectdb function in libpq.

  See also: pq_exec_params, pq_update_types.