jsonb.slt 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 January 7, 2021 from:
  14. #
  15. # https://github.com/postgres/postgres/blob/5940ffb221316ab73e6fdc780dfe9a07d4221ebb/src/test/regress/expected/join.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. mode cockroach
  21. # At the time of writing this file contains only PostgreSQL's subscript-related
  22. # jsonb tests, which constitute only a small fraction of the available jsonb
  23. # tests upstream.
  24. query T colnames
  25. select ('123'::jsonb)['a']
  26. ----
  27. jsonb
  28. NULL
  29. query T colnames
  30. select ('123'::jsonb)[0]
  31. ----
  32. jsonb
  33. NULL
  34. query T colnames
  35. select ('123'::jsonb)[NULL]
  36. ----
  37. jsonb
  38. NULL
  39. query T colnames
  40. select ('{"a": 1}'::jsonb)['a']
  41. ----
  42. jsonb
  43. 1
  44. query T colnames
  45. select ('{"a": 1}'::jsonb)[0]
  46. ----
  47. jsonb
  48. NULL
  49. query T colnames
  50. select ('{"a": 1}'::jsonb)['not_exist']
  51. ----
  52. jsonb
  53. NULL
  54. query T colnames
  55. select ('{"a": 1}'::jsonb)[NULL]
  56. ----
  57. jsonb
  58. NULL
  59. query T colnames
  60. select ('[1, "2", null]'::jsonb)['a']
  61. ----
  62. jsonb
  63. NULL
  64. query T colnames
  65. select ('[1, "2", null]'::jsonb)[0]
  66. ----
  67. jsonb
  68. 1
  69. query T colnames
  70. select ('[1, "2", null]'::jsonb)['1']
  71. ----
  72. jsonb
  73. "2"
  74. query error jsonb subscript type must be coercible to integer or text
  75. select ('[1, "2", null]'::jsonb)[1.0]
  76. query T colnames
  77. select ('[1, "2", null]'::jsonb)[2]
  78. ----
  79. jsonb
  80. null
  81. query T colnames
  82. select ('[1, "2", null]'::jsonb)[3]
  83. ----
  84. jsonb
  85. NULL
  86. query T colnames
  87. select ('[1, "2", null]'::jsonb)[-2]
  88. ----
  89. jsonb
  90. "2"
  91. query T colnames
  92. select ('[1, "2", null]'::jsonb)[1]['a']
  93. ----
  94. jsonb
  95. NULL
  96. query T colnames
  97. select ('[1, "2", null]'::jsonb)[1][0]
  98. ----
  99. jsonb
  100. NULL
  101. query T colnames
  102. select ('{"a": 1, "b": "c", "d": [1, 2, 3]}'::jsonb)['b']
  103. ----
  104. jsonb
  105. "c"
  106. query T colnames
  107. select ('{"a": 1, "b": "c", "d": [1, 2, 3]}'::jsonb)['d'];
  108. ----
  109. jsonb
  110. [1,2,3]
  111. query T colnames
  112. select ('{"a": 1, "b": "c", "d": [1, 2, 3]}'::jsonb)['d'][1]
  113. ----
  114. jsonb
  115. 2
  116. query T colnames
  117. select ('{"a": 1, "b": "c", "d": [1, 2, 3]}'::jsonb)['d']['a'];
  118. ----
  119. jsonb
  120. NULL
  121. query T colnames
  122. select ('{"a": {"a1": {"a2": "aaa"}}, "b": "bbb", "c": "ccc"}'::jsonb)['a']['a1']
  123. ----
  124. jsonb
  125. {"a2":"aaa"}
  126. query T colnames
  127. select ('{"a": {"a1": {"a2": "aaa"}}, "b": "bbb", "c": "ccc"}'::jsonb)['a']['a1']['a2']
  128. ----
  129. jsonb
  130. "aaa"
  131. query T colnames
  132. select ('{"a": {"a1": {"a2": "aaa"}}, "b": "bbb", "c": "ccc"}'::jsonb)['a']['a1']['a2']['a3']
  133. ----
  134. jsonb
  135. NULL
  136. query T colnames
  137. select ('{"a": ["a1", {"b1": ["aaa", "bbb", "ccc"]}], "b": "bb"}'::jsonb)['a'][1]['b1']
  138. ----
  139. jsonb
  140. ["aaa","bbb","ccc"]
  141. query T colnames
  142. select ('{"a": ["a1", {"b1": ["aaa", "bbb", "ccc"]}], "b": "bb"}'::jsonb)['a'][1]['b1'][2]
  143. ----
  144. jsonb
  145. "ccc"
  146. # slices are not supported
  147. query error jsonb subscript does not support slices
  148. select ('{"a": 1}'::jsonb)['a':'b']
  149. query error jsonb subscript does not support slices
  150. select ('[1, "2", null]'::jsonb)[1:2]
  151. query error jsonb subscript does not support slices
  152. select ('[1, "2", null]'::jsonb)[:2]
  153. query error jsonb subscript does not support slices
  154. select ('[1, "2", null]'::jsonb)[1:]