prepare.slt 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. # For more prepared statement tests, see `order_by.slt` and `test_bind_params`.
  10. statement ok
  11. CREATE TABLE t (a int);
  12. # INSERT
  13. statement ok
  14. PREPARE i1 AS
  15. INSERT INTO t(a) VALUES($1);
  16. statement ok
  17. EXECUTE i1(5);
  18. query I
  19. SELECT * FROM t;
  20. ----
  21. 5
  22. # INSERT ... RETURNING
  23. statement ok
  24. PREPARE i2 AS
  25. INSERT INTO t(a) VALUES($1 - 1) RETURNING $1 + 1;
  26. query I
  27. EXECUTE i2(7);
  28. ----
  29. 8
  30. query I
  31. SELECT * FROM t;
  32. ----
  33. 5
  34. 6
  35. query error db error: ERROR: operator is not unique: unknown \+ unknown
  36. PREPARE i3 AS
  37. INSERT INTO t(a) VALUES(4) RETURNING $1 + $1;
  38. statement ok
  39. PREPARE i3 AS
  40. INSERT INTO t(a) VALUES(4) RETURNING $1;
  41. query T
  42. EXECUTE i3('x');
  43. ----
  44. x
  45. query I valuesort
  46. SELECT * FROM t;
  47. ----
  48. 4
  49. 5
  50. 6
  51. statement ok
  52. PREPARE p1 AS
  53. SELECT $1 + $1::bigint;
  54. query I
  55. EXECUTE p1(5);
  56. ----
  57. 10
  58. statement ok
  59. PREPARE p2 AS
  60. SELECT $1::bigint + $1::bigint;
  61. query I
  62. EXECUTE p2(7);
  63. ----
  64. 14
  65. statement ok
  66. PREPARE p3 AS
  67. SELECT $1 || $1;
  68. query T
  69. EXECUTE p3('abc');
  70. ----
  71. abcabc
  72. statement ok
  73. PREPARE p4 AS
  74. SELECT $1::text || $1::bigint::text;
  75. query error db error: ERROR: invalid input syntax for type bigint: invalid digit found in string: "abc"
  76. EXECUTE p4('abc');
  77. query T
  78. EXECUTE p4('123');
  79. ----
  80. 123123
  81. statement ok
  82. PREPARE p5 AS
  83. SELECT $1, $1::bigint;
  84. query II
  85. EXECUTE p5(7);
  86. ----
  87. 0
  88. 7
  89. query error db error: ERROR: operator does not exist: bigint \|\| bigint
  90. PREPARE p6 AS
  91. SELECT $1 + $1::bigint, $1 || $1;
  92. query error db error: ERROR: operator does not exist: text \+ bigint
  93. PREPARE p7 AS
  94. SELECT $1 || $1, $1 + $1::bigint;
  95. query error db error: ERROR: there are contradicting constraints for the type of parameter \$1: should be both text and integer
  96. PREPARE p AS SELECT repeat($1, $1);