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 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);
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.
execute(conn,sqlquery)
Use the SQL ALTER statement to add the database column city
to the table Person
.
sqlquery = "ALTER TABLE Person ADD city varchar(30)";
execute(conn,sqlquery)
close(conn)
close
| execute
| postgresql