github-3256.slt 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. # Regression test for https://github.com/MaterializeInc/database-issues/issues/3256
  10. mode cockroach
  11. statement ok
  12. CREATE TABLE repro(f1 int, f2 string);
  13. statement ok
  14. INSERT INTO repro VALUES (1, null);
  15. statement ok
  16. CREATE VIEW repro_v AS SELECT f1, string_agg(f2, 'a') nullable_string_agg FROM repro GROUP BY f1;
  17. # Check that the query now works
  18. query IT
  19. SELECT * FROM repro_v
  20. ----
  21. 1 NULL
  22. # Check that the column is now marked as nullable if the input is null
  23. query T
  24. SELECT attnotnull FROM pg_catalog.pg_attribute WHERE attname = 'nullable_string_agg'
  25. ----
  26. false
  27. # Check that string_agg can be made non-nullable if the input is not null
  28. statement ok
  29. CREATE TABLE repro2(f1 int, f2 string NOT NULL);
  30. statement ok
  31. INSERT INTO repro2 VALUES (1, 'a');
  32. statement ok
  33. CREATE VIEW repro2_v AS SELECT f1, string_agg(f2, 'a') nonnull_string_agg FROM repro2 GROUP BY f1;
  34. query T
  35. SELECT attnotnull FROM pg_catalog.pg_attribute WHERE attname = 'nonnull_string_agg'
  36. ----
  37. true