Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc: upstream table name prefixed with database name #50

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 45 additions & 31 deletions sql/commands/sql-create-table.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,54 @@ CREATE TABLE [ IF NOT EXISTS ] table_name (

## Notes

For tables with primary key constraints, if you insert a new data record with an existing key, the new record will overwrite the existing record.

A [generated column](/docs/current/query-syntax-generated-columns/) that is defined with non-deterministic functions cannot be specified as part of the primary key. For example, if `A1` is defined as `current_timestamp()`, then it cannot be part of the primary key.

Names and unquoted identifiers are case-insensitive. Therefore, you must double-quote any of these fields for them to be case-sensitive. See also [Identifiers](/docs/current/sql-identifiers/).

The syntax for creating a table with connector settings and the supported connectors are the same as for creating a source. See [CREATE SOURCE](/docs/current/sql-create-source/) for a full list of supported connectors and data formats.

To know when a data record is loaded to RisingWave, you can define a column that is generated based on the processing time (`<column_name> timestamptz AS proctime()`) when creating the table or source. See also [proctime()](/docs/current/sql-function-datetime/#proctime).

For a table with schema from external connector, use `*` to represent all columns from the external connector first, so that you can define a generated column on table with an external connector. See the example below.

```js
CREATE TABLE from_kafka (
*,
gen_i32_field INT AS int32_field + 2,
PRIMARY KEY (some_key)
)
INCLUDE KEY AS some_key
[INCLUDE { header | offset | partition | timestamp } [AS <column_name>]]
WITH (
connector = 'kafka',
topic = 'test-rw-sink-upsert-avro',
properties.bootstrap.server = 'message_queue:29092'
)
FORMAT upsert ENCODE AVRO (
schema.registry = 'http://message_queue:8081'
);
```
- For tables with primary key constraints, if you insert a new data record with an existing key, the new record will overwrite the existing record.

- A [generated column](/docs/current/query-syntax-generated-columns/) that is defined with non-deterministic functions cannot be specified as part of the primary key. For example, if `A1` is defined as `current_timestamp()`, then it cannot be part of the primary key.

- Names and unquoted identifiers are case-insensitive. Therefore, you must double-quote any of these fields for them to be case-sensitive. See also [Identifiers](/docs/current/sql-identifiers/).

- The syntax for creating a table with connector settings and the supported connectors are the same as for creating a source. See [CREATE SOURCE](/docs/current/sql-create-source/) for a full list of supported connectors and data formats.

- To know when a data record is loaded to RisingWave, you can define a column that is generated based on the processing time (`<column_name> timestamptz AS proctime()`) when creating the table or source. See also [proctime()](/docs/current/sql-function-datetime/#proctime).

- For a table with schema from external connector, use `*` to represent all columns from the external connector first, so that you can define a generated column on table with an external connector. See the example below

```sql
CREATE TABLE from_kafka (
*,
gen_i32_field INT AS int32_field + 2,
PRIMARY KEY (some_key)
)
INCLUDE KEY AS some_key
[INCLUDE { header | offset | partition | timestamp } [AS <column_name>]]
WITH (
connector = 'kafka',
topic = 'test-rw-sink-upsert-avro',
properties.bootstrap.server = 'message_queue:29092'
)
FORMAT upsert ENCODE AVRO (
schema.registry = 'http://message_queue:8081'
);
```

- When creating a CDC table, the upstream table name should be prefixed with database name. See the example below:

```sql
CREATE TABLE shared_orders (
order_id INT,
order_date BIGINT,
customer_name VARCHAR,
price DECIMAL,
product_id INT,
order_status SMALLINT,
PRIMARY KEY (order_id)
) from mssql_source table 'mydb.dbo.wrong_orders';
```

## Parameters

| Parameter or clause | Description |
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Parameter or clause | Description |
| :-------------------------------- | :------------ |
| table\_name | The name of the table. If a schema name is given (for example, CREATE TABLE \<schema>.\<table> ...), then the table is created in the specified schema. Otherwise it is created in the current schema. |
| col\_name | The name of a column. |
| data\_type | The data type of a column. With the struct data type, you can create a nested table. Elements in a nested table need to be enclosed with angle brackets (\<>). |
Expand Down