insert-select.td 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. # Test INSERT INTO...SELECT. This must be a testdrive test to avoid symbiosis
  10. # in sqllogictest.
  11. > CREATE TABLE t (i INT, f REAL, t TEXT);
  12. > INSERT INTO t VALUES (1, 2, 'a'), (3, 4, 'b');
  13. > SELECT * FROM t ORDER BY i
  14. 1 2 a
  15. 3 4 b
  16. > CREATE TABLE u (i INT, f REAL, t TEXT);
  17. > INSERT INTO u VALUES (5, 6, 'c');
  18. > INSERT INTO t SELECT * FROM u;
  19. # Assignment casts are valid
  20. > CREATE TABLE bigger (i INT8, f FLOAT, t TEXT);
  21. > INSERT INTO bigger VALUES (7, 8, 'd');
  22. > INSERT INTO t SELECT * FROM bigger;
  23. # Obliquely go through SELECT * FROM ( VALUES ... )
  24. > INSERT INTO t SELECT * FROM (
  25. VALUES (9.1::numeric, 10, 'e')
  26. );
  27. > SELECT * FROM t ORDER BY i
  28. 1 2 a
  29. 3 4 b
  30. 5 6 c
  31. 7 8 d
  32. 9 10 e
  33. # Multiple connections
  34. > CREATE TABLE c (a int);
  35. > INSERT INTO c VALUES (1);
  36. > CREATE TABLE s (a int);
  37. $ postgres-connect name=writer url=postgres://materialize:materialize@${testdrive.materialize-sql-addr}
  38. # In-flight txns don't affect updates/deletes, and vice versa
  39. $ postgres-execute connection=writer
  40. BEGIN;
  41. INSERT INTO s VALUES (2);
  42. > INSERT INTO c SELECT * FROM s;
  43. > SELECT a FROM c
  44. 1
  45. $ postgres-execute connection=writer
  46. INSERT INTO s VALUES (3);
  47. COMMIT;
  48. > INSERT INTO c SELECT * FROM s;
  49. > SELECT a FROM c
  50. 1
  51. 2
  52. 3
  53. > BEGIN;
  54. > SELECT a FROM c
  55. 1
  56. 2
  57. 3
  58. $ postgres-execute connection=writer
  59. INSERT INTO c SELECT * FROM s;
  60. > SELECT a FROM c
  61. 1
  62. 2
  63. 3
  64. > COMMIT;
  65. # Every value from s should be duplicated in c
  66. > SELECT a FROM s
  67. 2
  68. 3
  69. > SELECT a FROM c;
  70. 1
  71. 2
  72. 2
  73. 3
  74. 3