99 parent : ' commands'
1010---
1111
12- ` CREATE TABLE ` defines a table that is persisted in durable storage. In
13- Materialize, you can create:
12+ ` CREATE TABLE ` defines a table that is persisted in durable storage.
13+
14+ In Materialize, you can create:
1415
1516- User-populated tables. User-populated tables can be written to (i.e.,
1617 [ ` INSERT ` ] /[ ` UPDATE ` ] /[ ` DELETE ` ] ) by the user.
@@ -24,9 +25,12 @@ Materialize, you can create:
2425 the associated ** public** webhook URL, which is automatically created with the
2526 table creation.
2627
27- Tables can be joined with other tables, materialized views, and views. Tables in
28- Materialize are similar to tables in standard relational databases: they consist
29- of rows and columns where the columns are fixed when the table is created.
28+ Tables in Materialize are similar to tables in standard relational databases:
29+ they consist of rows and columns where the columns are fixed when the table is
30+ created.
31+
32+ Tables can be joined with other tables, materialized views, and views; and you
33+ can create views/materialized views/indexes on tables.
3034
3135## Syntax
3236
@@ -59,7 +63,6 @@ CREATE [TEMP|TEMPORARY] TABLE <table_name> (
5963To create a table from a [ source] ( /sql/create-source/ ) connected (via
6064native connector) to an external database system:
6165
62-
6366{{< note >}}
6467
6568- {{< include-md file="shared-content/create-table-from-source-readonly.md" >}}
@@ -70,7 +73,7 @@ native connector) to an external database system:
7073{{</ note >}}
7174
7275``` mzsql
73- CREATE TABLE <table_name> FROM SOURCE <source_name> (REFERENCE <ref_object >)
76+ CREATE TABLE <table_name> FROM SOURCE <source_name> (REFERENCE <upstream_table >)
7477[WITH (
7578 TEXT COLUMNS (<column_name> [, ...]) -- Available for PostgreSQL and MySQL
7679 | EXCLUDE COLUMNS (<column_name> [, ...]) -- Available for MySQL and SQL Server
@@ -316,6 +319,11 @@ guidelines](/sql/identifiers/#naming-restrictions).
316319
317320{{< include-md file="shared-content/create-table-supported-types.md" >}}
318321
322+ ### Source-populated tables and snapshotting
323+
324+ {{< include-md file="shared-content/create-table-from-source-snapshotting.md"
325+ > }}
326+
319327### Known limitations
320328
321329Tables do not currently support:
@@ -352,10 +360,7 @@ The privileges required to execute the command are:
352360{{% include-example file="examples/create-table/example_user_defined_table"
353361 example="create-table" %}}
354362
355- #### Verify table creation
356-
357363Once a table is created, you can inspect the table with various ` SHOW ` commands.
358-
359364For example:
360365
361366- [ ` SHOW TABLES ` ] ( /sql/show-tables/ )
@@ -371,7 +376,7 @@ For example:
371376#### Read/write to the new table
372377
373378Once a user-populated table is created, you can perform CRUD
374- (Create/Read/Update/Write) operations.
379+ (Create/Read/Update/Write) operations on it .
375380
376381{{% include-example file="examples/create-table/example_user_defined_table"
377382 example="write-to-table" %}}
@@ -381,36 +386,20 @@ Once a user-populated table is created, you can perform CRUD
381386
382387### Create a table (PostgreSQL Source)
383388
384- The following example creates a table from a PostgreSQL source using the `CREATE
385- TABLE FROM SOURCE` syntax.
386-
387389{{< note >}}
388390
389391The example assumes you have configured your upstream PostgreSQL 11+ (i.e.,
390392enabled logical replication, created the publication for the various tables and
391393replication user, and updated the network configuration).
392394
393- For details about configuring your upstream system, see the integration
394- guides:
395-
396- <ul style =" column-count :2 " >
397-
398- - [ AlloyDB for PostgreSQL] ( /ingest-data/postgres/alloydb/ )
399- - [ Amazon Aurora for PostgreSQL] ( /ingest-data/postgres/amazon-aurora/ )
400- - [ Amazon RDS for PostgreSQL] ( /ingest-data/postgres/amazon-rds/ )
401- - [ Azure DB for PostgreSQL] ( /ingest-data/postgres/azure-db/ )
402- - [ Google Cloud SQL for PostgreSQL] ( /ingest-data/postgres/cloud-sql/ )
403- - [ Neon] ( /ingest-data/postgres/neon/ )
404- - [ Self-hosted PostgreSQL] ( /ingest-data/postgres/self-hosted/ )
405- </ul >
395+ For details about configuring your upstream system, see the [ PostgreSQL
396+ integration guides] ( /ingest-data/postgres/#supported-versions-and-services ) .
406397
407398{{</ note >}}
408399
409400{{% include-example file="examples/create-table/example_postgres_table"
410401 example="create-table" %}}
411402
412- #### Verify table creation
413-
414403Once a table is created, you can inspect the table with various ` SHOW `
415404commands. For example:
416405
@@ -427,78 +416,127 @@ commands. For example:
427416#### Query the read-only table
428417
429418{{< include-md file="shared-content/create-table-from-source-readonly.md" >}}
419+
430420{{< include-md file="shared-content/create-table-from-source-snapshotting.md"
431421> }}
432422
433- Once the snapshotting process completes, you can:
434-
435- - Query the table:
423+ Once the snapshotting process completes, you can query the table:
436424
437- {{% include-example file="examples/create-table/example_postgres_table"
425+ {{% include-example file="examples/create-table/example_postgres_table"
438426 example="read-from-table" %}}
439427
440- - Join with other tables, create views on the tables, etc:
428+ ### Create a table (MySQL Source)
441429
442- {{% include-example file="examples/create-table/example_postgres_table"
443- example="create-view-from-tables" %}}
430+ {{< note >}}
431+
432+ The example assumes you have configured your upstream MySQL 5.7+ (i.e.,
433+ enabled GTID-based binlog replication, created the
434+ replication user, and updated the network configuration as needed).
435+
436+ For details about configuring your upstream system, see the [ MySQL
437+ integration guides] ( /ingest-data/mysql/#supported-versions-and-services ) .
438+
439+ {{</ note >}}
440+
441+ {{% include-example file="examples/create-table/example_mysql_table"
442+ example="create-table" %}}
443+
444+ Once a table is created, you can inspect the table with various ` SHOW `
445+ commands. For example:
446+
447+ - [ ` SHOW TABLES ` ] ( /sql/show-tables/ )
448+
449+ {{% include-example file="examples/create-table/example_mysql_table"
450+ example="show-tables" %}}
451+
452+ - [ ` SHOW COLUMNS ` ] ( /sql/show-tables/ )
453+
454+ {{% include-example file="examples/create-table/example_mysql_table"
455+ example="show-columns" %}}
456+
457+ #### Query the read-only table
458+
459+ {{< include-md file="shared-content/create-table-from-source-readonly.md" >}}
460+
461+ {{< include-md file="shared-content/create-table-from-source-snapshotting.md"
462+ > }}
463+
464+ Once the snapshotting process completes, you can query the table:
465+
466+ {{% include-example file="examples/create-table/example_mysql_table"
467+ example="read-from-table" %}}
444468
445469### Create a table (Kafka Source)
446470
447- The following example creates a table from a Kafka (or Redpanda) source using
448- the ` CREATE TABLE FROM SOURCE ` syntax.
471+ {{< tip >}}
472+ The same syntax may be used for Redpanda.
473+ {{</ tip >}}
449474
450475{{< tabs >}}
451476{{< tab "FORMAT AVRO">}}
452477
453- ** Using Confluent Schema Registry**
478+ {{% include-example file="examples/create-table/example_kafka_table_avro"
479+ example="create-table" %}}
454480
455- ``` mzsql
456- CREATE SOURCE avro_source
457- FROM KAFKA CONNECTION kafka_connection (TOPIC 'test_topic')
458- FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_connection;
459- ```
481+ Once a table is created, you can inspect the table with various ` SHOW `
482+ commands. For example:
483+
484+ - [ ` SHOW TABLES ` ] ( /sql/show-tables/ )
485+
486+ {{% include-example file="examples/create-table/example_kafka_table_avro"
487+ example="show-tables" %}}
488+
489+ - [ ` SHOW COLUMNS ` ] ( /sql/show-tables/ )
490+
491+ {{% include-example file="examples/create-table/example_kafka_table_avro"
492+ example="show-columns" %}}
493+
494+ #### Query the read-only table
495+
496+ {{< include-md file="shared-content/create-table-from-source-readonly.md" >}}
497+
498+ {{< include-md file="shared-content/create-table-from-source-snapshotting.md"
499+ > }}
500+
501+ {{% include-example file="examples/create-table/example_kafka_table_avro"
502+ example="read-from-table" %}}
460503
461504{{< /tab >}}
462505{{< tab "FORMAT JSON">}}
463506
464- The following example creates a read-only table from a Kafka source, where the
465- messages are JSON records.
507+ {{% include- example file="examples/create- table/example_kafka_table_json"
508+ example="create-table" %}}
466509
467- ``` mzsql
468- /* This example assumes:
469- - That you have defined a connection to Kafka.
470- - That you have created a source using that connection.
471- For example:
472-
473- CREATE SECRET kafka_secret AS 'mypassword';
474- CREATE CONNECTION kafka_connection TO KAFKA (
475- BROKER 'host:port', -- substitute
476- SECURITY PROTOCOL = 'SASL_PLAINTEXT', -- substitute
477- SASL MECHANISMS = 'SCRAM-SHA-256', -- substitute
478- SASL USERNAME = 'myuser', -- substitute
479- SASL PASSWORD = SECRET kafka_secret
480- );
481-
482- CREATE SOURCE kafka_json_source
483- FROM KAFKA CONNECTION kafka_connection (TOPIC 'test_topic');
484- */
485- CREATE TABLE my_json_table
486- FROM SOURCE kafka_json_source
487- FORMAT JSON;
488- ```
510+ Once a table is created, you can inspect the table with various ` SHOW `
511+ commands. For example:
489512
490- By default, creates a table ` my_json_table ` with 1 column named ` data ` of type
491- [ ` jsonb ` ] ( /sql/types/jsonb/ ) . You can include additional columns using the
492- ` INCLUDE ` options.
513+ - [ ` SHOW TABLES ` ] ( /sql/show-tables/ )
493514
494- You can create a view on top of your table that parses the ` data ` value into
495- individual columns with the required data types. To help with this task, you can
496- paste a sample JSON document into [ this ** JSON parsing
497- widget ** ] ( /sql/types/jsonb/#parsing ) to create the view.
515+ {{% include-example file="examples/create- table/example_kafka_table_json"
516+ example="show-tables" %}}
517+
518+ - [ ` SHOW COLUMNS ` ] ( /sql/show-tables/ )
498519
499- {{< json-parser >}}
520+ {{% include-example file="examples/create-table/example_kafka_table_json"
521+ example="show-columns" %}}
522+
523+ #### Query the read-only table
524+
525+ {{< include-md file="shared-content/create-table-from-source-readonly.md" >}}
526+
527+ {{< include-md file="shared-content/create-table-from-source-snapshotting.md"
528+ > }}
529+
530+ Once the snapshotting process completes, you can query the table:
531+
532+ {{% include-example file="examples/create-table/example_kafka_table_json"
533+ example="read-from-table" %}}
500534
535+ #### Create a view from table
501536
537+ {{% include-example file="examples/create-table/example_kafka_table_json"
538+ example="create-a-view-from-table" %}}
539+
502540{{< /tab >}}
503541
504542{{< tab "FORMAT TEXT/BYTES">}}
0 commit comments