Skip to content

Commit 63efef0

Browse files
committed
temp
1 parent 6f8dbec commit 63efef0

File tree

3 files changed

+96
-6
lines changed

3 files changed

+96
-6
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
- name: "create-table"
2+
description: |
3+
To create new **read-only** tables from a source, in the `CREATE TABLE FROM
4+
SOURCE` statement, specify the table in the publication using the
5+
`REFERENCE` field.
6+
7+
The following example creates **read-only** tables `items` and `orders` that
8+
are populated from the corresponding `items` and `orders` tables from the
9+
MySQL source `mz_source`.
10+
11+
{{< note >}}
12+
13+
- Although the example creates the tables with the same names as the
14+
upstream tables, the tables in Materialize can have names that differ from
15+
the referenced table names.
16+
17+
- For supported MySQL data types, refer to [supported
18+
types](#upstream-sources-and-supported-data-types).
19+
20+
- You can create multiple tables that reference the same upstream table.
21+
22+
{{< /note >}}
23+
24+
code: |
25+
/* This example assumes:
26+
- In the upstream MySQL, you have:
27+
- Enabled GTID-based binlog replication
28+
- Defined a replication user and password with the appropriate access.
29+
- In Materialize,
30+
- You have defined the connection to the upstream MySQL.
31+
- You have used the connection to create a source; e.g.,
32+
CREATE SECRET mysql_password AS '<replication user password>'; -- substitute
33+
CREATE CONNECTION mysql_connection TO MYSQL (
34+
HOST '<hostname>', -- substitute
35+
USER <replication user>, -- substitute
36+
PASSWORD SECRET mysql_password
37+
-- [, <network security configuration> ]
38+
);
39+
40+
CREATE SOURCE mz_source
41+
FROM MYSQL CONNECTION mysql_connection;
42+
*/
43+
44+
CREATE TABLE items
45+
FROM SOURCE mz_source(REFERENCE public.items)
46+
;
47+
CREATE TABLE orders
48+
FROM SOURCE mz_source(REFERENCE public.orders)
49+
;
50+
51+
- name: "show-tables"
52+
description: |
53+
To verify that the table has been created, you can run [`SHOW
54+
TABLES`](/sql/show-tables/) to list all tables in the current [schema](/sql/namespaces/#namespace-hierarchy):
55+
code: |
56+
SHOW TABLES;
57+
results: |
58+
The results should include the tables `items` and `orders`:
59+
60+
```hc {hl_lines="3-4"}
61+
| name | comment |
62+
| ----------- | ------- |
63+
| items | |
64+
| orders | |
65+
```
66+
67+
- name: "show-columns"
68+
description: |
69+
Inspect the table columns using the [`SHOW COLUMNS`](/sql/show-columns/) command:
70+
code: |
71+
SHOW COLUMNS FROM items;
72+
SHOW COLUMNS FROM orders;
73+
results: |
74+
The results should display information on the table columns. The types
75+
should match those from the upstream table.
76+
77+
For the list of supported PostgreSQL data types, refer to [supported
78+
types](#upstream-sources-and-supported-data-types).
79+
80+
- name: "read-from-table"
81+
code: |
82+
SELECT * FROM items;
83+
84+
- name: "create-view-from-tables"
85+
code: |
86+
CREATE VIEW orders_view AS
87+
SELECT o.*,i.price,o.quantity * i.price as subtotal
88+
FROM orders as o
89+
JOIN items as i
90+
ON o.item = i.item;

doc/user/data/examples/create-table/example_postgres_table.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@
4545
*/
4646
4747
CREATE TABLE items
48-
FROM SOURCE mz_source(REFERENCE items)
48+
FROM SOURCE mz_source(REFERENCE public.items)
4949
;
5050
CREATE TABLE orders
51-
FROM SOURCE mz_source(REFERENCE orders)
51+
FROM SOURCE mz_source(REFERENCE public.orders)
5252
;
5353
5454
- name: "show-tables"
@@ -75,8 +75,7 @@
7575
SHOW COLUMNS FROM orders;
7676
results: |
7777
The results should display information on the table columns. The types
78-
should match those from the upstream table with the exception of those that
79-
were explicitly converted to `text` in the `WITH` clause.
78+
should match those from the upstream table.
8079
8180
For the list of supported PostgreSQL data types, refer to [supported
8281
types](#upstream-sources-and-supported-data-types).

doc/user/shared-content/postsgres-unsupported-type-handling.md renamed to doc/user/shared-content/postgres-unsupported-type-handling.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Replicating tables that contain **unsupported data types** is possible via the
2-
[`TEXT COLUMNS` option]. When decoded as `text`, the specified
3-
columns will not have the expected PostgreSQL type features. For example:
2+
[`TEXT COLUMNS`](/sql/create-table/#syntax). When decoded as `text`, the
3+
specified columns will not have the expected PostgreSQL type features. For
4+
example:
45

56
* [`enum`]: When decoded as `text`, the resulting `text` values will
67
not observe the implicit ordering of the original PostgreSQL `enum`; instead,

0 commit comments

Comments
 (0)