duplicate-table-names.td 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. > CREATE SCHEMA other;
  10. > CREATE TABLE a (c int)
  11. > CREATE TABLE b (c int)
  12. > CREATE TABLE generate_series (c int)
  13. > CREATE TABLE other.a (c int)
  14. > SELECT * FROM a, other.a;
  15. c c
  16. ---
  17. # alias avoids collision
  18. > SELECT * FROM a, a AS b;
  19. c c
  20. ---
  21. # subquery avoids collision
  22. > SELECT * FROM a, (SELECT * FROM a);
  23. c c
  24. ---
  25. # joined tables collide
  26. ! SELECT * FROM a, a;
  27. contains:table name "a" specified more than once
  28. ! SELECT * FROM b, (SELECT * FROM a, a);
  29. contains:table name "a" specified more than once
  30. ! SELECT * FROM other.a, other.a;
  31. contains:table name "a" specified more than once
  32. ! SELECT * FROM a LEFT JOIN a ON TRUE;
  33. contains:table name "a" specified more than once
  34. ! SELECT * FROM (a NATURAL JOIN b) NATURAL JOIN a;
  35. contains:table name "a" specified more than once
  36. ! SELECT * FROM (a NATURAL JOIN b) NATURAL JOIN b;
  37. contains:table name "b" specified more than once
  38. ! DELETE FROM a USING a;
  39. contains:table name "a" specified more than once
  40. # alias introduces collision
  41. ! SELECT * FROM a, b AS a;
  42. contains:table name "a" specified more than once
  43. ! SELECT * FROM a, other.a AS a;
  44. contains:table name "a" specified more than once
  45. ! SELECT * FROM a AS z, b AS z;
  46. contains:table name "z" specified more than once
  47. ! SELECT * FROM a, (SELECT * FROM a) AS a;
  48. contains:table name "a" specified more than once
  49. # table function names
  50. ! SELECT * FROM generate_series, generate_series(1,2)
  51. contains:table name "generate_series" specified more than once
  52. ! SELECT * FROM a AS generate_series, generate_series(1,2)
  53. contains:table name "generate_series" specified more than once
  54. ! SELECT * FROM generate_series AS a, generate_series(1,2) AS a
  55. contains:table name "a" specified more than once
  56. ! SELECT * FROM a, generate_series(1,2) AS a
  57. contains:table name "a" specified more than once
  58. # CTEs
  59. ! WITH a AS (SELECT 1) SELECT * FROM a, a;
  60. contains:table name "a" specified more than once