Re: Difference between text_pattern_ops and varchar_pattern_ops

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: David Morgenstern <d(dot)morgenstern(at)synedra(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Difference between text_pattern_ops and varchar_pattern_ops
Date: 2021-06-25 13:38:51
Message-ID: 2737119.1624628331@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

David Morgenstern <d(dot)morgenstern(at)synedra(dot)com> writes:
> Can somebody explain why text_pattern_ops can be used on varchar
> columns, considering it can’t be used for bpchar columns?

The underlying rule there is that an opclass can be applied to an index
column if the column's actual type is binary-coercible to what the opclass
expects. varchar is binary-coercible to text, since they're basically the
same type. bpchar is not, because we must insert a coercion function that
strips any trailing blanks. (Essentially, the restriction exists because
the index machinery won't cope with such intermediate functions.)

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message 周书林 2021-06-26 04:56:21 What is the difference between context of "sighup", "super-backend", and "backend" in pg_settings?
Previous Message Laurenz Albe 2021-06-25 11:43:05 Re: Difference between text_pattern_ops and varchar_pattern_ops