extract.slt 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. mode cockroach
  10. statement ok
  11. CREATE TABLE data (input text)
  12. statement ok
  13. INSERT INTO data VALUES
  14. ('asdfjkl'), ('foo'), ('asdf'), ('testing,123'),
  15. (NULL), ('jkl'), ('some,csv')
  16. query TTT colnames
  17. SELECT data.*, reg.*
  18. FROM data, regexp_extract('(asdf)|(?P<foo>jkl)', data.input) reg
  19. ORDER BY data.input
  20. ----
  21. input column1 foo
  22. asdf asdf NULL
  23. asdfjkl asdf NULL
  24. jkl NULL jkl
  25. # TODO(brennan): test that the regex columns have the correct nullability, once
  26. # they actually do (database-issues#612).
  27. query TTT colnames
  28. SELECT data.*, csv.* FROM data, csv_extract(2, data.input) csv
  29. ORDER BY data.input
  30. ----
  31. input column1 column2
  32. some,csv some csv
  33. testing,123 testing 123
  34. query error db error: ERROR: csv_extract number of columns must be a positive integer literal
  35. SELECT * FROM data, (VALUES (2)) ncols, csv_extract(ncols.column1, data.input)
  36. query error db error: ERROR: csv_extract number of columns must be a positive integer literal
  37. SELECT * FROM data, csv_extract((SELECT 2), data.input)
  38. query error db error: ERROR: attempt to create relation with too many columns, 8193 max: 8192
  39. SELECT * FROM data, csv_extract(8193, data.input)
  40. statement ok
  41. SELECT * FROM data, csv_extract(8192, data.input)