beam icon indicating copy to clipboard operation
beam copied to clipboard

CI Text should be usable with toTsVector

Open AnthonySuper opened this issue 5 years ago • 3 comments

In postgresql, the following works fine:

CREATE EXTENSION citext;
CREATE TABLE examples ( example citext PRIMARY KEY);
INSERT INTO examples(example) VALUES ('my cool example'), ('my even cooler example'), ('my lame example');
SELECT * FROM examples WHERE to_tsvector(examples.example) @@ to_tsquery('cool');

However, in Beam, you can't use toTsVector on columns of type CI Text.

I see two (relatively) easy way of solving this:

  1. Add an instance of IsSqlExpressionStringType for CI Text
  2. Create a new class, named something like IsValidTsquerySource, add Text and CI Text to it, and then use that as the constraint for toTsvector instead

I can implement either (I think), but wanted to ask before writing any code.

AnthonySuper avatar Mar 20 '20 23:03 AnthonySuper

IsSqlExpressionStringType is now BeamSqlBackendIsString, but otherwise I believe approach (1) is better. I'm not very familiar with citext, it does support all normal string functions and not just comparisons, right? The Postgres docs aren't super clear on this.

kmicklas avatar Aug 22 '20 19:08 kmicklas

I believe so, although I'm not 100% certain. I suppose that would probably be something to ask the postgres mailing lists?

I will note that I've used citext extensively on both personal and professional projects and (from my recollection) have never encountered any place where it behaves differently from text other than the obvious case-insensitivity.

AnthonySuper avatar Aug 23 '20 02:08 AnthonySuper

Perfect, adding the BeamSqlBackendIsString instance should be the way to go then.

kmicklas avatar Aug 23 '20 13:08 kmicklas