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.
execute(conn,sqlquery)
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)";
execute(conn,sqlquery)
Close Database Connection
close(conn)
See Also
postgresql
| close
| execute
Related Topics
- Insert Data into Database Table Using PostgreSQL Native Interface
- Roll Back Data in Database Using PostgreSQL Native Interface