tables.td 23 KB

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