regex.slt 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # Copyright 1994, Regents of the University of California.
  2. # Copyright 1996-2019 PostgreSQL Global Development Group.
  3. # Copyright Materialize, Inc. and contributors. All rights reserved.
  4. #
  5. # Use of this software is governed by the Business Source License
  6. # included in the LICENSE file at the root of this repository.
  7. #
  8. # As of the Change Date specified in that file, in accordance with
  9. # the Business Source License, use of this software will be governed
  10. # by the Apache License, Version 2.0.
  11. #
  12. # This file is derived from the regression test suite in PostgreSQL.
  13. # The original file was retrieved on October 23, 2020 from:
  14. #
  15. # https://github.com/postgres/postgres/blob/783f0cc64dcc05e3d112a06b1cd181e5a1ca9099/src/test/regress/expected/regex.out
  16. #
  17. # The original source code is subject to the terms of the PostgreSQL
  18. # license, a copy of which can be found in the LICENSE file at the
  19. # root of this repository.
  20. statement ok
  21. CREATE TABLE strings (s text)
  22. statement ok
  23. INSERT INTO strings VALUES ('abc'), ('123')
  24. query T
  25. select regexp_match('abc', '')
  26. ----
  27. {""}
  28. query T
  29. select regexp_match('abc', 'bc')
  30. ----
  31. {bc}
  32. query T
  33. select regexp_match('abc', 'd') is null
  34. ----
  35. true
  36. query T
  37. select regexp_match('abc', '(B)(c)', 'i')
  38. ----
  39. {b,c}
  40. query T
  41. select regexp_match('abc', '(b)(c)(d)?')
  42. ----
  43. {b,c,NULL}
  44. query T rowsort
  45. select regexp_match(s, '^.(.)')[1] FROM strings
  46. ----
  47. 2
  48. b
  49. # Test nullability
  50. query B
  51. SELECT regexp_match('a', 'a') IS NULL
  52. ----
  53. false
  54. query B
  55. SELECT regexp_match(NULL, 'a') IS NULL
  56. ----
  57. true
  58. query B
  59. SELECT regexp_match('a', NULL) IS NULL
  60. ----
  61. true
  62. query B
  63. SELECT regexp_match(NULL, 'a', 'i') IS NULL
  64. ----
  65. true
  66. query B
  67. SELECT regexp_match('a', NULL, 'i') IS NULL
  68. ----
  69. true
  70. query B
  71. SELECT regexp_match('a', 'a', NULL) IS NULL
  72. ----
  73. true