"David G. Johnston" <david.g.johns...@gmail.com> writes: > On Fri, Feb 9, 2024, 10:12 PG Doc comments form <nore...@postgresql.org> > wrote: >> The documentation implies that the data types text and varchar are >> equivalent, but this is not the case with this test in Postgresql version >> 16.
> Fair point. But I'd rather further emphasize that char should just be > avoided so this and other unexpected outcomes simply do not manifest in a > real database scenario. Rather than try and document how odd it's behavior > is when dealing with intra-textual type conversions. Yeah, this is less about varchar acting oddly and more about char acting oddly. The short answer though is that text is a preferred type, varchar is not, and that makes a difference when resolving whether to apply text's or char's equality operator. You can detect how it's being handled with EXPLAIN: regression=# explain verbose SELECT vc = ch AS vc_ch FROM test; QUERY PLAN --------------------------------------------------------------- Seq Scan on pg_temp.test (cost=0.00..17.88 rows=630 width=1) Output: ((vc)::bpchar = ch) (2 rows) regression=# explain verbose SELECT txt = ch AS txt_ch FROM test; QUERY PLAN --------------------------------------------------------------- Seq Scan on pg_temp.test (cost=0.00..19.45 rows=630 width=1) Output: (txt = (ch)::text) (2 rows) regards, tom lane