@@ -1662,3 +1662,117 @@ values ('2023-01-01T00:00:00.666'::timestamp(6)) union all values ('2023-01-01T0
16621662
16631663query error numeric field overflow
16641664SELECT '1e-307'::float8::numeric
1665+
1666+ statement ok
1667+ CREATE TABLE t1(a varchar(3));
1668+
1669+ statement ok
1670+ CREATE TABLE t2(b varchar(4));
1671+
1672+ statement error db error: ERROR: value too long for type character varying\(3\)
1673+ INSERT INTO t1 VALUES ('123456');
1674+
1675+ # From the Postgres docs: https://www.postgresql.org/docs/current/datatype-character.html
1676+ # "An attempt to store a longer string into a column of these types will result in an error, unless the excess
1677+ # characters are all spaces, in which case the string will be truncated to the maximum length. (This somewhat bizarre
1678+ # exception is required by the SQL standard.)"
1679+ statement ok
1680+ INSERT INTO t1 VALUES ('111 ');
1681+
1682+ statement ok
1683+ INSERT INTO t1 VALUES ('123');
1684+
1685+ statement ok
1686+ INSERT INTO t2 VALUES ('1234');
1687+
1688+ query T multiline
1689+ EXPLAIN WITH (TYPES)
1690+ (SELECT * FROM t1) UNION ALL (SELECT * FROM t2);
1691+ ----
1692+ Explained Query:
1693+ Union // { types: "(varchar?)" }
1694+ ReadStorage materialize.public.t1 // { types: "(varchar(3)?)" }
1695+ ReadStorage materialize.public.t2 // { types: "(varchar(4)?)" }
1696+
1697+ Source materialize.public.t1
1698+ Source materialize.public.t2
1699+
1700+ Target cluster: quickstart
1701+
1702+ EOF
1703+
1704+ query T
1705+ (SELECT * FROM t1) UNION ALL (SELECT * FROM t2);
1706+ ----
1707+ 111
1708+ 123
1709+ 1234
1710+
1711+ query T
1712+ (SELECT * FROM t2) UNION ALL (SELECT * FROM t1);
1713+ ----
1714+ 111
1715+ 123
1716+ 1234
1717+
1718+ statement ok
1719+ CREATE TABLE t3(b char(2));
1720+
1721+ statement ok
1722+ INSERT INTO t3 VALUES ('ab');
1723+
1724+ query T multiline
1725+ EXPLAIN WITH (TYPES)
1726+ (SELECT * FROM t1) UNION ALL (SELECT * FROM t3);
1727+ ----
1728+ Explained Query:
1729+ Union // { types: "(varchar?)" }
1730+ ReadStorage materialize.public.t1 // { types: "(varchar(3)?)" }
1731+ Project (#1) // { types: "(varchar?)" }
1732+ Map (text_to_varchar[len=None](#0)) // { types: "(char(2)?, varchar?)" }
1733+ ReadStorage materialize.public.t3 // { types: "(char(2)?)" }
1734+
1735+ Source materialize.public.t1
1736+ Source materialize.public.t3
1737+
1738+ Target cluster: quickstart
1739+
1740+ EOF
1741+
1742+ query T
1743+ (SELECT * FROM t1) UNION ALL (SELECT * FROM t3);
1744+ ----
1745+ ab
1746+ 111
1747+ 123
1748+
1749+ statement ok
1750+ CREATE TABLE t4(b char(3));
1751+
1752+ statement ok
1753+ INSERT INTO t4 VALUES ('ab ');
1754+
1755+ query T multiline
1756+ EXPLAIN WITH (TYPES)
1757+ (SELECT * FROM t3) UNION (SELECT * FROM t4);
1758+ ----
1759+ Explained Query:
1760+ Distinct project=[#0] // { types: "(char?)" }
1761+ Union // { types: "(char?)" }
1762+ ReadStorage materialize.public.t3 // { types: "(char(2)?)" }
1763+ ReadStorage materialize.public.t4 // { types: "(char(3)?)" }
1764+
1765+ Source materialize.public.t3
1766+ Source materialize.public.t4
1767+
1768+ Target cluster: quickstart
1769+
1770+ EOF
1771+
1772+ # Trailing spaces are treated as semantically insignificant in both Postgres and Materialize, so the above
1773+ # 'ab' and 'ab ' end up deduplicated.
1774+ # See also in char-varchar-distinct.td
1775+ query T
1776+ (SELECT * FROM t3) UNION (SELECT * FROM t4);
1777+ ----
1778+ ab
0 commit comments