Main Content

rmoptions

Remove PostgreSQL native interface connection options

Description

example

opts = rmoptions(opts,option) removes one or more specified connection options from the SQLConnectionOptions object opts.

Examples

collapse all

Edit an existing PostgreSQL native interface data source for a PostgreSQL database. Set an additional driver-specific option, and test the database connection. Then, remove the additional driver-specific option, and test and save the data source.

Retrieve the existing PostgreSQL native interface data source.

datasource = "PostgreSQLDataSource";
opts = databaseConnectionOptions(datasource)
opts = 
  SQLConnectionOptions with properties:

              DataSourceName: "PostgreSQLDataSource"
                      Vendor: "PostgreSQL"

                DatabaseName: "toystore_doc"
                      Server: "dbtb00"
                  PortNumber: 5432

opts is an SQLConnectionOptions object with these properties:

  • DataSourceName — Name of the data source

  • Vendor — Database vendor name

  • DatabaseName — Name of the database

  • Server — Name of the database server

  • PortNumber — Port number

Add a driver-specific connection option by using a name-value pair argument. The option specifies a timeout value for establishing the database connection. opts contains a new property for the additional connection option.

opts = setoptions(opts,"connect_timeout",20)
opts = 
  SQLConnectionOptions with properties:

              DataSourceName: "PostgreSQLDataSource"
                      Vendor: "PostgreSQL"

                DatabaseName: "toystore_doc"
                      Server: "dbtb00"
                  PortNumber: 5432

	Additional Connection Options:

             connect_timeout: 20

Test the database connection with a user name and password. The testConnection function returns the logical 1, which indicates the database connection is successful.

username = "dbdev";
password = "matlab";
status = testConnection(opts,username,password)
status = logical
   1

Remove the driver-specific option for specifying a timeout value. The opts object no longer contains the connect_timeout property.

opts = rmoptions(opts,"connect_timeout")
opts = 
  SQLConnectionOptions with properties:

              DataSourceName: "PostgreSQLDataSource"
                      Vendor: "PostgreSQL"

                DatabaseName: "toystore_doc"
                      Server: "dbtb00"
                  PortNumber: 5432

Test the database connection again.

username = "dbdev";
password = "matlab";
status = testConnection(opts,username,password)
status = logical
   1

Save the data source.

saveAsDataSource(opts)

Input Arguments

collapse all

Database connection options, specified as an SQLConnectionOptions object.

PostgreSQL native interface connection option, specified as a character vector, string scalar, cell array of character vectors, or string array. Specify the name of one or more PostgreSQL native interface connection options or driver-specific connection options.

Example: ["DatabaseName" "Server" "PortNumber"]

Example: "connect_timeout"

Data Types: char | string | cell

Output Arguments

collapse all

Database connection options, returned as an SQLConnectionOptions object.

Introduced in R2020b