Main Content

Create Table and Add Column Using PostgreSQL Native Interface

This example shows how to connect to a database and manage the database structure using the PostgreSQL native interface. You can manage the database structure using the execute function.

Create Database Connection

Create a PostgreSQL native interface database connection to a PostgreSQL database using the data source name, user name, and password.

datasource = "PostgreSQLDataSource";
username = "dbdev";
password = "matlab";
conn = postgresql(datasource,username,password);

Create Database Table

Use the SQL CREATE statement to create the database table Person.

sqlquery = strcat("CREATE TABLE Person(lastname varchar,", ...
    "firstname varchar,address varchar,age numeric)");

Create the table in the database using the database connection.


Add Database Column

Use the SQL ALTER statement to add the database column city to the table Person.

sqlquery = "ALTER TABLE Person ADD city varchar(30)"; 

Close Database Connection


See Also

| |

Related Topics

External Websites