Rob <postgresql@mintsoft.net> writes:
> Basically, if a table exists with a PK which is CHAR(n) and a query is
> sent with VARCHAR or CHAR then it uses an Index Scan. If the query is
> sent with TEXT as the type then postgresql casts the column to TEXT
> (rather than the value to CHAR) and it does a Seq Scan.
Yeah, this is an artifact of the fact that text is considered a
"preferred type" so it wins out in the parser's choice of which
type to promote to. See
https://www.postgresql.org/docs/current/typeconv-oper.html
> I guess the root question is: is TEXT supposed to be identical to
> VARCHAR in all scenarios?
It's not for this purpose, because varchar isn't a preferred type.
FWIW, my recommendation for this sort of thing is almost always
to not use CHAR(n). The use-case for that datatype pretty much
disappeared with the last IBM Model 029 card punch.
regards, tom lane