char-varchar-joins.td 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #
  10. # Confirm that joins and the equality comparisons inherent to join
  11. # procesisng work properly with the CHAR data type and trailing spaces.
  12. #
  13. > CREATE TABLE char_table (f1 CHAR(20));
  14. > INSERT INTO char_table VALUES ('a'), ('a '), ('a '), (''), (' '), (NULL);
  15. > CREATE TABLE varchar_table (f1 VARCHAR(20));
  16. > INSERT INTO varchar_table VALUES ('a'), ('a '), ('a '), (''), (' '), (NULL);
  17. > CREATE TABLE text_table (f1 TEXT);
  18. > INSERT INTO text_table VALUES ('a'), ('a '), ('a '), (''), (' '), (NULL);
  19. > SELECT * FROM char_table, varchar_table WHERE char_table.f1 = varchar_table.f1;
  20. " " ""
  21. " " ""
  22. "a " "a"
  23. "a " "a"
  24. "a " "a"
  25. " " " "
  26. " " " "
  27. "a " "a "
  28. "a " "a "
  29. "a " "a "
  30. "a " "a "
  31. "a " "a "
  32. "a " "a "
  33. > SELECT * FROM char_table AS a1, char_table AS a2 WHERE a1.f1 = a2.f1;
  34. " " " "
  35. " " " "
  36. " " " "
  37. " " " "
  38. "a " "a "
  39. "a " "a "
  40. "a " "a "
  41. "a " "a "
  42. "a " "a "
  43. "a " "a "
  44. "a " "a "
  45. "a " "a "
  46. "a " "a "
  47. # Comparisons with TEXT are strict byte-by-byte
  48. > SELECT * FROM char_table, text_table WHERE char_table.f1 = text_table.f1;
  49. " " ""
  50. " " ""
  51. "a " "a"
  52. "a " "a"
  53. "a " "a"