tables.td 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. $ set-arg-default single-replica-cluster=quickstart
  10. $ set-regex match=cluster1|quickstart replacement=<CLUSTER_NAME>
  11. ! INSERT INTO t VALUES (1, 'a');
  12. contains:unknown catalog item 't'
  13. ! SHOW CREATE TABLE t;
  14. contains:unknown catalog item 't'
  15. > CREATE TABLE t (a int, b text NOT NULL)
  16. > SHOW CREATE TABLE t;
  17. name create_sql
  18. ------------------------
  19. materialize.public.t "CREATE TABLE materialize.public.t (a pg_catalog.int4, b pg_catalog.text NOT NULL);"
  20. > CREATE TABLE s (a int DEFAULT 1)
  21. > DROP TABLE s;
  22. > CREATE TABLE s (a int DEFAULT (1))
  23. > DROP TABLE s;
  24. > CREATE TABLE s (a date DEFAULT now())
  25. > DROP TABLE s;
  26. > CREATE TABLE s (a date DEFAULT now() + interval '1 day');
  27. > DROP TABLE s;
  28. > CREATE TABLE s (a int NOT NULL DEFAULT NULL)
  29. > DROP TABLE s;
  30. ! CREATE TABLE s (a date DEFAULT 42)
  31. contains:DEFAULT expression does not support casting from integer to date
  32. ! CREATE TABLE s (a int, b int DEFAULT a + 3)
  33. contains:column "a" does not exist
  34. ! CREATE TABLE t (a int, b int, a int);
  35. contains:column "a" specified more than once
  36. > SELECT * FROM t;
  37. > SHOW TABLES;
  38. name comment
  39. -------------
  40. t ""
  41. > SHOW SOURCES;
  42. name type cluster comment
  43. ------------------------------
  44. > SHOW INDEXES ON t;
  45. > CREATE DEFAULT INDEX on t
  46. > SHOW INDEXES ON t
  47. name on cluster key comment
  48. -----------------------------------------------------------------------------------
  49. t_primary_idx t <CLUSTER_NAME> {a,b} ""
  50. > DROP INDEX t_primary_idx
  51. > SHOW COLUMNS in t;
  52. name nullable type comment
  53. --------------------------------------
  54. a true integer ""
  55. b false text ""
  56. > SHOW COLUMNS in t WHERE name = 'a'
  57. a true integer ""
  58. > SHOW COLUMNS in t LIKE 'b%'
  59. b false text ""
  60. > INSERT INTO t VALUES (1, 'a');
  61. > SELECT * FROM t;
  62. a b
  63. ---------
  64. 1 "a"
  65. $ set schema={
  66. "name": "row",
  67. "type": "record",
  68. "fields": [
  69. {"name": "id", "type": "string"},
  70. {"name": "a", "type": "long"},
  71. {"name": "b", "type": "long"}
  72. ]
  73. }
  74. $ kafka-create-topic topic=data
  75. $ kafka-ingest format=avro topic=data schema=${schema} timestamp=1
  76. {"id": "valid1", "a": 2, "b": 1}
  77. > CREATE CONNECTION kafka_conn
  78. TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  79. > CREATE SOURCE data
  80. IN CLUSTER ${arg.single-replica-cluster}
  81. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-data-${testdrive.seed}')
  82. > CREATE TABLE data_tbl FROM SOURCE data (REFERENCE "testdrive-data-${testdrive.seed}")
  83. FORMAT AVRO USING SCHEMA '${schema}'
  84. > SELECT * FROM t CROSS JOIN data_tbl
  85. 1 a valid1 2 1
  86. # We don't actually care about these results. We just want to ensure that
  87. # joining a table with a logging source selects some reasonable timestamp,
  88. # rather than e.g. blocking forever, or producing an error about being
  89. # unable to select a timestamp.
  90. # In case the environment has other replicas
  91. > SET cluster_replica = r1
  92. > SELECT * FROM t CROSS JOIN mz_introspection.mz_dataflow_operators LIMIT 0
  93. > DROP SOURCE data CASCADE
  94. # Ensure that tables work after creating a custom index, and that the custom
  95. # index is not subject to the same no-drop restriction as the default index.
  96. > CREATE INDEX t_custom_idx ON t (b)
  97. > SELECT * FROM t;
  98. a b
  99. ---------
  100. 1 "a"
  101. > DROP INDEX t_custom_idx
  102. > INSERT INTO t VALUES (2, 'b'), (NULL, 'c');
  103. > SELECT * FROM t;
  104. a b
  105. ----------
  106. 1 "a"
  107. 2 "b"
  108. <null> "c"
  109. > INSERT INTO t SELECT * FROM t WHERE a IS NULL;
  110. ! INSERT INTO t VALUES (1);
  111. contains:null value in column "b" violates not-null constraint
  112. ! INSERT INTO t VALUES (1, NULL);
  113. contains:null value in column "b" violates not-null constraint
  114. ! INSERT INTO t VALUES ('d', 4);
  115. contains:invalid input syntax for type integer: invalid digit found in string: "d"
  116. # Test that the INSERT body can be a SELECT query.
  117. > INSERT INTO t SELECT 3, 'd'
  118. # Test that literal coercion occurs in simple VALUES clauses....
  119. > INSERT INTO t VALUES ('4', 'e')
  120. # ...but not in complicated VALUES clauses, per PostgreSQL.
  121. ! INSERT INTO t VALUES ('5', 'f') LIMIT 0
  122. contains:column "a" is of type integer but expression is of type text
  123. # Test that assignment casts occur when possible...
  124. > INSERT INTO t VALUES (5.0, 'f');
  125. > INSERT INTO t VALUES (6.7::float8, 'g')
  126. # ...but not when impossible.
  127. ! INSERT INTO t VALUES (DATE '2020-01-01', 'bad')
  128. contains:column "a" is of type integer but expression is of type date
  129. ! INSERT INTO t (b, a) VALUES ('bad', DATE '2020-01-01')
  130. contains:column "a" is of type integer but expression is of type date
  131. # Attempting to insert JSON into an int column is particularly interesting.
  132. # While there is an "explicit" cast from `jsonb` to `int`, there is no
  133. # "assignment" cast, and INSERT is only allowed to use assignment/implicit
  134. # casts.
  135. ! INSERT INTO t VALUES (JSON '1', 'bad')
  136. contains:column "a" is of type integer but expression is of type jsonb
  137. > SELECT * FROM t;
  138. a b
  139. ------------
  140. 1 "a"
  141. 2 "b"
  142. <null> "c"
  143. <null> "c"
  144. 3 "d"
  145. 4 "e"
  146. 5 "f"
  147. 7 "g"
  148. > CREATE TABLE s (a int NOT NULL);
  149. ! INSERT INTO s VALUES (1 + NULL);
  150. contains:null value in column "a" violates not-null constraint
  151. ! INSERT INTO s VALUES (case when now() = now() then NULL else 2 end);
  152. contains:null value in column "a" violates not-null constraint
  153. ! INSERT INTO s SELECT (case when now() = now() then NULL else 2 end);
  154. contains:null value in column "a" violates not-null constraint
  155. > CREATE TABLE n (a int);
  156. > INSERT INTO n VALUES (NULL);
  157. ! INSERT INTO s SELECT * FROM n;
  158. contains:null value in column "a" violates not-null constraint
  159. > DROP TABLE n
  160. > CREATE TABLE v (a timestamptz);
  161. > INSERT INTO v VALUES (now());
  162. ! CREATE INDEX ON v (now())
  163. contains:cannot materialize call to current_timestamp
  164. ! CREATE INDEX ON v (mz_now())
  165. contains:cannot materialize call to mz_now
  166. ! CREATE INDEX ON v (mz_version())
  167. contains:cannot materialize call to mz_version
  168. > DROP TABLE IF EXISTS s;
  169. > DROP TABLE t;
  170. > DROP TABLE IF EXISTS t;
  171. ! SELECT * from t;
  172. contains:unknown catalog item 't'
  173. ! SHOW INDEXES ON t;
  174. contains:unknown catalog item 't'
  175. > SHOW TABLES;
  176. name comment
  177. -------------
  178. v ""
  179. > SHOW TABLES LIKE 'foo'
  180. > SHOW TABLES LIKE 'v%'
  181. v ""
  182. > SHOW TABLES WHERE name = 'v'
  183. v ""
  184. > SHOW SOURCES;
  185. name type cluster comment
  186. --------------------------------
  187. > CREATE TABLE t (a int, b text NOT NULL)
  188. > SELECT * FROM t;
  189. > CREATE VIEW view AS SELECT 1
  190. ! INSERT INTO view VALUES (1)
  191. contains:cannot insert into view 'materialize.public.view'
  192. ! INSERT INTO mz_kafka_sinks VALUES ('bad', 'bad')
  193. contains:cannot insert into system table 'mz_catalog.mz_kafka_sinks'
  194. > CREATE TABLE j (time TIMESTAMP NOT NULL);
  195. # Verify that INSERT value is desugared.
  196. > INSERT INTO j VALUES ((TIMESTAMP '2020-08-28 15:08:00'));
  197. # Test that a fairly large INSERT completes.
  198. > CREATE TABLE large (a int)
  199. > INSERT INTO large VALUES
  200. (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), (18), (19), (20), (21), (22), (23), (24), (25), (26), (27), (28), (29), (30), (31), (32), (33), (34), (35), (36), (37), (38), (39), (40), (41), (42), (43), (44), (45), (46), (47), (48), (49), (50), (51), (52), (53), (54), (55), (56), (57), (58), (59), (60), (61), (62), (63), (64), (65), (66), (67), (68), (69), (70), (71), (72), (73), (74), (75), (76), (77), (78), (79), (80), (81), (82), (83), (84), (85), (86), (87), (88), (89), (90), (91), (92), (93), (94), (95), (96), (97), (98), (99), (100), (101), (102), (103), (104), (105), (106), (107), (108), (109), (110), (111), (112), (113), (114), (115), (116), (117), (118), (119), (120), (121), (122), (123), (124), (125), (126), (127), (128),
  201. (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), (18), (19), (20), (21), (22), (23), (24), (25), (26), (27), (28), (29), (30), (31), (32), (33), (34), (35), (36), (37), (38), (39), (40), (41), (42), (43), (44), (45), (46), (47), (48), (49), (50), (51), (52), (53), (54), (55), (56), (57), (58), (59), (60), (61), (62), (63), (64), (65), (66), (67), (68), (69), (70), (71), (72), (73), (74), (75), (76), (77), (78), (79), (80), (81), (82), (83), (84), (85), (86), (87), (88), (89), (90), (91), (92), (93), (94), (95), (96), (97), (98), (99), (100), (101), (102), (103), (104), (105), (106), (107), (108), (109), (110), (111), (112), (113), (114), (115), (116), (117), (118), (119), (120), (121), (122), (123), (124), (125), (126), (127), (128),
  202. (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), (18), (19), (20), (21), (22), (23), (24), (25), (26), (27), (28), (29), (30), (31), (32), (33), (34), (35), (36), (37), (38), (39), (40), (41), (42), (43), (44), (45), (46), (47), (48), (49), (50), (51), (52), (53), (54), (55), (56), (57), (58), (59), (60), (61), (62), (63), (64), (65), (66), (67), (68), (69), (70), (71), (72), (73), (74), (75), (76), (77), (78), (79), (80), (81), (82), (83), (84), (85), (86), (87), (88), (89), (90), (91), (92), (93), (94), (95), (96), (97), (98), (99), (100), (101), (102), (103), (104), (105), (106), (107), (108), (109), (110), (111), (112), (113), (114), (115), (116), (117), (118), (119), (120), (121), (122), (123), (124), (125), (126), (127), (128),
  203. (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), (18), (19), (20), (21), (22), (23), (24), (25), (26), (27), (28), (29), (30), (31), (32), (33), (34), (35), (36), (37), (38), (39), (40), (41), (42), (43), (44), (45), (46), (47), (48), (49), (50), (51), (52), (53), (54), (55), (56), (57), (58), (59), (60), (61), (62), (63), (64), (65), (66), (67), (68), (69), (70), (71), (72), (73), (74), (75), (76), (77), (78), (79), (80), (81), (82), (83), (84), (85), (86), (87), (88), (89), (90), (91), (92), (93), (94), (95), (96), (97), (98), (99), (100), (101), (102), (103), (104), (105), (106), (107), (108), (109), (110), (111), (112), (113), (114), (115), (116), (117), (118), (119), (120), (121), (122), (123), (124), (125), (126), (127), (128),
  204. (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), (18), (19), (20), (21), (22), (23), (24), (25), (26), (27), (28), (29), (30), (31), (32), (33), (34), (35), (36), (37), (38), (39), (40), (41), (42), (43), (44), (45), (46), (47), (48), (49), (50), (51), (52), (53), (54), (55), (56), (57), (58), (59), (60), (61), (62), (63), (64), (65), (66), (67), (68), (69), (70), (71), (72), (73), (74), (75), (76), (77), (78), (79), (80), (81), (82), (83), (84), (85), (86), (87), (88), (89), (90), (91), (92), (93), (94), (95), (96), (97), (98), (99), (100), (101), (102), (103), (104), (105), (106), (107), (108), (109), (110), (111), (112), (113), (114), (115), (116), (117), (118), (119), (120), (121), (122), (123), (124), (125), (126), (127), (128),
  205. (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), (18), (19), (20), (21), (22), (23), (24), (25), (26), (27), (28), (29), (30), (31), (32), (33), (34), (35), (36), (37), (38), (39), (40), (41), (42), (43), (44), (45), (46), (47), (48), (49), (50), (51), (52), (53), (54), (55), (56), (57), (58), (59), (60), (61), (62), (63), (64), (65), (66), (67), (68), (69), (70), (71), (72), (73), (74), (75), (76), (77), (78), (79), (80), (81), (82), (83), (84), (85), (86), (87), (88), (89), (90), (91), (92), (93), (94), (95), (96), (97), (98), (99), (100), (101), (102), (103), (104), (105), (106), (107), (108), (109), (110), (111), (112), (113), (114), (115), (116), (117), (118), (119), (120), (121), (122), (123), (124), (125), (126), (127), (128),
  206. (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), (18), (19), (20), (21), (22), (23), (24), (25), (26), (27), (28), (29), (30), (31), (32), (33), (34), (35), (36), (37), (38), (39), (40), (41), (42), (43), (44), (45), (46), (47), (48), (49), (50), (51), (52), (53), (54), (55), (56), (57), (58), (59), (60), (61), (62), (63), (64), (65), (66), (67), (68), (69), (70), (71), (72), (73), (74), (75), (76), (77), (78), (79), (80), (81), (82), (83), (84), (85), (86), (87), (88), (89), (90), (91), (92), (93), (94), (95), (96), (97), (98), (99), (100), (101), (102), (103), (104), (105), (106), (107), (108), (109), (110), (111), (112), (113), (114), (115), (116), (117), (118), (119), (120), (121), (122), (123), (124), (125), (126), (127), (128),
  207. (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), (18), (19), (20), (21), (22), (23), (24), (25), (26), (27), (28), (29), (30), (31), (32), (33), (34), (35), (36), (37), (38), (39), (40), (41), (42), (43), (44), (45), (46), (47), (48), (49), (50), (51), (52), (53), (54), (55), (56), (57), (58), (59), (60), (61), (62), (63), (64), (65), (66), (67), (68), (69), (70), (71), (72), (73), (74), (75), (76), (77), (78), (79), (80), (81), (82), (83), (84), (85), (86), (87), (88), (89), (90), (91), (92), (93), (94), (95), (96), (97), (98), (99), (100), (101), (102), (103), (104), (105), (106), (107), (108), (109), (110), (111), (112), (113), (114), (115), (116), (117), (118), (119), (120), (121), (122), (123), (124), (125), (126), (127), (128),
  208. (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), (18), (19), (20), (21), (22), (23), (24), (25), (26), (27), (28), (29), (30), (31), (32), (33), (34), (35), (36), (37), (38), (39), (40), (41), (42), (43), (44), (45), (46), (47), (48), (49), (50), (51), (52), (53), (54), (55), (56), (57), (58), (59), (60), (61), (62), (63), (64), (65), (66), (67), (68), (69), (70), (71), (72), (73), (74), (75), (76), (77), (78), (79), (80), (81), (82), (83), (84), (85), (86), (87), (88), (89), (90), (91), (92), (93), (94), (95), (96), (97), (98), (99), (100), (101), (102), (103), (104), (105), (106), (107), (108), (109), (110), (111), (112), (113), (114), (115), (116), (117), (118), (119), (120), (121), (122), (123), (124), (125), (126), (127), (128),
  209. (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), (18), (19), (20), (21), (22), (23), (24), (25), (26), (27), (28), (29), (30), (31), (32), (33), (34), (35), (36), (37), (38), (39), (40), (41), (42), (43), (44), (45), (46), (47), (48), (49), (50), (51), (52), (53), (54), (55), (56), (57), (58), (59), (60), (61), (62), (63), (64), (65), (66), (67), (68), (69), (70), (71), (72), (73), (74), (75), (76), (77), (78), (79), (80), (81), (82), (83), (84), (85), (86), (87), (88), (89), (90), (91), (92), (93), (94), (95), (96), (97), (98), (99), (100), (101), (102), (103), (104), (105), (106), (107), (108), (109), (110), (111), (112), (113), (114), (115), (116), (117), (118), (119), (120), (121), (122), (123), (124), (125), (126), (127), (128),
  210. (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), (18), (19), (20), (21), (22), (23), (24), (25), (26), (27), (28), (29), (30), (31), (32), (33), (34), (35), (36), (37), (38), (39), (40), (41), (42), (43), (44), (45), (46), (47), (48), (49), (50), (51), (52), (53), (54), (55), (56), (57), (58), (59), (60), (61), (62), (63), (64), (65), (66), (67), (68), (69), (70), (71), (72), (73), (74), (75), (76), (77), (78), (79), (80), (81), (82), (83), (84), (85), (86), (87), (88), (89), (90), (91), (92), (93), (94), (95), (96), (97), (98), (99), (100), (101), (102), (103), (104), (105), (106), (107), (108), (109), (110), (111), (112), (113), (114), (115), (116), (117), (118), (119), (120), (121), (122), (123), (124), (125), (126), (127), (128),
  211. (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), (18), (19), (20), (21), (22), (23), (24), (25), (26), (27), (28), (29), (30), (31), (32), (33), (34), (35), (36), (37), (38), (39), (40), (41), (42), (43), (44), (45), (46), (47), (48), (49), (50), (51), (52), (53), (54), (55), (56), (57), (58), (59), (60), (61), (62), (63), (64), (65), (66), (67), (68), (69), (70), (71), (72), (73), (74), (75), (76), (77), (78), (79), (80), (81), (82), (83), (84), (85), (86), (87), (88), (89), (90), (91), (92), (93), (94), (95), (96), (97), (98), (99), (100), (101), (102), (103), (104), (105), (106), (107), (108), (109), (110), (111), (112), (113), (114), (115), (116), (117), (118), (119), (120), (121), (122), (123), (124), (125), (126), (127), (128),
  212. (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), (18), (19), (20), (21), (22), (23), (24), (25), (26), (27), (28), (29), (30), (31), (32), (33), (34), (35), (36), (37), (38), (39), (40), (41), (42), (43), (44), (45), (46), (47), (48), (49), (50), (51), (52), (53), (54), (55), (56), (57), (58), (59), (60), (61), (62), (63), (64), (65), (66), (67), (68), (69), (70), (71), (72), (73), (74), (75), (76), (77), (78), (79), (80), (81), (82), (83), (84), (85), (86), (87), (88), (89), (90), (91), (92), (93), (94), (95), (96), (97), (98), (99), (100), (101), (102), (103), (104), (105), (106), (107), (108), (109), (110), (111), (112), (113), (114), (115), (116), (117), (118), (119), (120), (121), (122), (123), (124), (125), (126), (127), (128),
  213. (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), (18), (19), (20), (21), (22), (23), (24), (25), (26), (27), (28), (29), (30), (31), (32), (33), (34), (35), (36), (37), (38), (39), (40), (41), (42), (43), (44), (45), (46), (47), (48), (49), (50), (51), (52), (53), (54), (55), (56), (57), (58), (59), (60), (61), (62), (63), (64), (65), (66), (67), (68), (69), (70), (71), (72), (73), (74), (75), (76), (77), (78), (79), (80), (81), (82), (83), (84), (85), (86), (87), (88), (89), (90), (91), (92), (93), (94), (95), (96), (97), (98), (99), (100), (101), (102), (103), (104), (105), (106), (107), (108), (109), (110), (111), (112), (113), (114), (115), (116), (117), (118), (119), (120), (121), (122), (123), (124), (125), (126), (127), (128),
  214. (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), (18), (19), (20), (21), (22), (23), (24), (25), (26), (27), (28), (29), (30), (31), (32), (33), (34), (35), (36), (37), (38), (39), (40), (41), (42), (43), (44), (45), (46), (47), (48), (49), (50), (51), (52), (53), (54), (55), (56), (57), (58), (59), (60), (61), (62), (63), (64), (65), (66), (67), (68), (69), (70), (71), (72), (73), (74), (75), (76), (77), (78), (79), (80), (81), (82), (83), (84), (85), (86), (87), (88), (89), (90), (91), (92), (93), (94), (95), (96), (97), (98), (99), (100), (101), (102), (103), (104), (105), (106), (107), (108), (109), (110), (111), (112), (113), (114), (115), (116), (117), (118), (119), (120), (121), (122), (123), (124), (125), (126), (127), (128),
  215. (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), (18), (19), (20), (21), (22), (23), (24), (25), (26), (27), (28), (29), (30), (31), (32), (33), (34), (35), (36), (37), (38), (39), (40), (41), (42), (43), (44), (45), (46), (47), (48), (49), (50), (51), (52), (53), (54), (55), (56), (57), (58), (59), (60), (61), (62), (63), (64), (65), (66), (67), (68), (69), (70), (71), (72), (73), (74), (75), (76), (77), (78), (79), (80), (81), (82), (83), (84), (85), (86), (87), (88), (89), (90), (91), (92), (93), (94), (95), (96), (97), (98), (99), (100), (101), (102), (103), (104), (105), (106), (107), (108), (109), (110), (111), (112), (113), (114), (115), (116), (117), (118), (119), (120), (121), (122), (123), (124), (125), (126), (127), (128);
  216. # Test INSERT with default values
  217. > DROP TABLE IF EXISTS t;
  218. > CREATE TABLE t (a int DEFAULT 4, b int DEFAULT 6 * 7)
  219. > INSERT INTO t (a) VALUES (1);
  220. > INSERT INTO t DEFAULT VALUES;
  221. > SELECT * FROM t;
  222. a b
  223. ------
  224. 1 42
  225. 4 42
  226. # Test INSERT with column specifiers
  227. > DROP TABLE IF EXISTS t;
  228. > CREATE TABLE t (a int, b text not null, c int)
  229. > INSERT INTO t (b, c, a) VALUES ('a', 2, 1), ('b', NULL, 3);
  230. > select * from t;
  231. a b c
  232. -------------------
  233. 1 "a" 2
  234. 3 "b" <null>
  235. > INSERT INTO t (b) VALUES ('c');
  236. > select * from t;
  237. a b c
  238. -------------------
  239. 1 "a" 2
  240. 3 "b" <null>
  241. <null> "c" <null>
  242. ! INSERT INTO t (notpresent, a, c) VALUES ('str', 1, 2);
  243. contains:column "notpresent" of relation "materialize.public.t" does not exist
  244. ! INSERT INTO t (a, b, c) VALUES ('str', 1, 2);
  245. contains:invalid input syntax for type integer: invalid digit found in string: "str"
  246. ! INSERT INTO t (b, a, c) VALUES (1, 'str', 2);
  247. contains:invalid input syntax for type integer: invalid digit found in string: "str"
  248. ! INSERT INTO t (d, c, b, a) VALUES (1, 1, 1, 'str');
  249. contains:column "d" of relation "materialize.public.t" does not exist
  250. ! INSERT INTO t (a) VALUES (1);
  251. contains:null value in column "b" violates not-null constraint
  252. ! INSERT INTO t (a) VALUES (1, 'str');
  253. contains:INSERT has more expressions than target columns
  254. ! INSERT INTO t (a, b, c) VALUES (1);
  255. contains:INSERT has more target columns than expressions
  256. ! INSERT INTO t (a, a) VALUES (1, 'str')
  257. contains:column "a" specified more than once
  258. # Test pg_table_is_visible.
  259. > CREATE SCHEMA non_default
  260. > CREATE TABLE non_default.hidden (dummy int)
  261. > SELECT name, pg_table_is_visible(oid) AS visible FROM mz_tables WHERE schema_id != 'u1' AND id LIKE 'u%'
  262. name visible
  263. ---------------
  264. hidden false
  265. j true
  266. large true
  267. t true
  268. v true
  269. # As in PostgreSQL, tables with no columns are permitted, but they are
  270. # pretty useless.
  271. > CREATE TABLE nocols ();
  272. ! INSERT INTO nocols VALUES (1)
  273. contains:INSERT has more expressions than target columns
  274. > SELECT count(*) FROM nocols
  275. 0
  276. > INSERT INTO nocols SELECT UNION ALL SELECT
  277. > SELECT count(*) FROM nocols
  278. 2
  279. ! SELECT DISTINCT * FROM nocols
  280. contains:SELECT DISTINCT must have at least one column
  281. # Test that show columns preserves the column order
  282. > CREATE TABLE column_order (b int, a int);
  283. > SHOW COLUMNS FROM column_order
  284. name nullable type comment
  285. ------------------------------
  286. b true integer ""
  287. a true integer ""
  288. # Test that the underlying Persist shard gets cleaned up on DROP.
  289. > CREATE TABLE shard_drop_test (a int, b text);
  290. > INSERT INTO shard_drop_test VALUES (1, 'hello');
  291. > CREATE TABLE shard_drop_test_empty (a int, b text);
  292. $ set-from-sql var=shard-drop-test-id
  293. SELECT id FROM mz_tables WHERE name = 'shard_drop_test';
  294. $ set-from-sql var=shard-drop-test-empty-id
  295. SELECT id FROM mz_tables WHERE name = 'shard_drop_test_empty';
  296. # Wait for the mz_storage_shards table to get updated.
  297. > SELECT COUNT(shard_id) FROM mz_internal.mz_storage_shards WHERE object_id IN ('${shard-drop-test-id}', '${shard-drop-test-empty-id}');
  298. 2
  299. $ set-from-sql var=shard-drop-test-shard-id
  300. SELECT shard_id FROM mz_internal.mz_storage_shards WHERE object_id = '${shard-drop-test-id}';
  301. $ set-from-sql var=shard-drop-test-empty-shard-id
  302. SELECT shard_id FROM mz_internal.mz_storage_shards WHERE object_id = '${shard-drop-test-empty-id}';
  303. > DROP TABLE shard_drop_test;
  304. > DROP TABLE shard_drop_test_empty;
  305. > SELECT COUNT(*) FROM mz_internal.mz_storage_shards WHERE object_id IN ('${shard-drop-test-id}', '${shard-drop-test-empty-id}');
  306. 0
  307. $ check-shard-tombstone shard-id=${shard-drop-test-shard-id}
  308. # TODO(parkmycar): The since and upper of the shard are empty, but the controller still has it's handle registered.
  309. # $ check-shard-tombstone shard-id=${shard-drop-test-empty-shard-id}