pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedDifference between text_pattern_ops and varchar_pattern_ops
3+ messages / 3 participants
[nested] [flat]
* Difference between text_pattern_ops and varchar_pattern_ops
@ 2021-06-25 10:29 David Morgenstern <d.morgenstern@synedra.com>
2021-06-25 11:43 ` Re: Difference between text_pattern_ops and varchar_pattern_ops Laurenz Albe <laurenz.albe@cybertec.at>
2021-06-25 13:38 ` Re: Difference between text_pattern_ops and varchar_pattern_ops Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 2 replies; 3+ messages in thread
From: David Morgenstern @ 2021-06-25 10:29 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Hello all,
The documentation for operator classes (https://www.postgresql.org/docs/current/indexes-opclass.html <https://www.postgresql.org/docs/current/indexes-opclass.html;) seems to indicate that text_pattern_ops should only be used for text columns and varchar_pattern_ops should be used for varchar columns. However today I stumbled upon an index using text_pattern_ops on a varchar column. Everything seems to be working fine. Now I am wondering what the difference between text_pattern_ops and varchar_pattern_ops might be.
Can somebody explain why text_pattern_ops can be used on varchar columns, considering it can’t be used for bpchar columns? And are there any downsides in doing this (aside from my confusion of course)?
Minimal example:
CREATE TABLE film (
title varchar(40)
);
CREATE INDEX film_title_ix ON film USING btree (title text_pattern_ops);
Any thoughts on this subject are greatly appreciated.
Kind regards
David Morgenstern=
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Difference between text_pattern_ops and varchar_pattern_ops
2021-06-25 10:29 Difference between text_pattern_ops and varchar_pattern_ops David Morgenstern <d.morgenstern@synedra.com>
@ 2021-06-25 11:43 ` Laurenz Albe <laurenz.albe@cybertec.at>
1 sibling, 0 replies; 3+ messages in thread
From: Laurenz Albe @ 2021-06-25 11:43 UTC (permalink / raw)
To: David Morgenstern <d.morgenstern@synedra.com>; pgsql-general@lists.postgresql.org
On Fri, 2021-06-25 at 12:29 +0200, David Morgenstern wrote:
> The documentation for operator classes (https://www.postgresql.org/docs/current/indexes-opclass.html)
> seems to indicate that text_pattern_ops should only be used for text columns
> and varchar_pattern_ops should be used for varchar columns.
> However today I stumbled upon an index using text_pattern_ops on a varchar column.
> Everything seems to be working fine. Now I am wondering what the difference
> between text_pattern_ops and varchar_pattern_ops might be.
>
> Can somebody explain why text_pattern_ops can be used on varchar columns, considering it
> can’t be used for bpchar columns? And are there any downsides in doing this
> (aside from my confusion of course)?
https://www.postgresql.org/message-id/flat/A737B7A37273E048B164557ADEF4A58B17CCE003%40ntex2010i.host...
Yours,
Laurenz Albe
--
+43-670-6056265
CYBERTEC PostgreSQL International GmbH
Gröhrmühlgasse 26, A-2700 Wiener Neustadt
Web: https://www.cybertec-postgresql.com
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Difference between text_pattern_ops and varchar_pattern_ops
2021-06-25 10:29 Difference between text_pattern_ops and varchar_pattern_ops David Morgenstern <d.morgenstern@synedra.com>
@ 2021-06-25 13:38 ` Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 3+ messages in thread
From: Tom Lane @ 2021-06-25 13:38 UTC (permalink / raw)
To: David Morgenstern <d.morgenstern@synedra.com>; +Cc: pgsql-general@lists.postgresql.org
David Morgenstern <d.morgenstern@synedra.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
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2021-06-25 13:38 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-06-25 10:29 Difference between text_pattern_ops and varchar_pattern_ops David Morgenstern <d.morgenstern@synedra.com>
2021-06-25 11:43 ` Laurenz Albe <laurenz.albe@cybertec.at>
2021-06-25 13:38 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox