Realtime Compute uses the CREATE TABLE
statement to define the schema of a result table for output data and how data is
written into a target result table.
Data can be written into the target storage system by using one of the following methods: append and update.
- Append: If the result table is stored in Log Service, Message Queue (MQ), or an ApsaraDB for RDS database with the primary key undefined, output data is appended to the result table. The original data in the result table is not modified.
- Update: If the result table is stored in an ApsaraDB for RDS database or a Hadoop
database with a primary key defined, output data is written into the result table
as follows:
- If the value for the primary key does not exist in the result table, the data record is inserted into the database.
- If the value for the primary key exists in the result table, the existing data record in the database is overwritten.
Syntax
CREATE TABLE tableName
(columnName dataType [, columnName dataType ]*)
[ WITH (propertyName=propertyValue [, propertyName=propertyValue ]*) ];
Example
CREATE TABLE rds_output(
id INT,
len INT,
content VARCHAR,
PRIMARY KEY(id)
) WITH (
type='rds',
url='yourDatabaseURL',
tableName='yourTableName',
userName='yourDatabaseUserName',
password='yourDatabasePassword'
);