Creating or modifying a tsquery from PL/pgSQL

From: Tobia Conforto <tobia(dot)conforto(at)gruppo4(dot)eu>
To: pgsql-general(at)postgresql(dot)org
Subject: Creating or modifying a tsquery from PL/pgSQL
Date: 2016-06-17 13:46:23
Message-ID: 65CA8C0E-1BF2-48F4-854D-402307064FC5@gruppo4.eu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I'd like to convert a plain search string into a tsquery, much like plainto_tsquery(), but enabling prefix searches (:*) for every word.

I've come up with this:

select regexp_replace(
plainto_tsquery('english', 'text to search')::text,
'''(?= |$)', ''':*', 'g'
)::tsquery;
--> 'text':* & 'search':*

Is this the best way to do it, without writing C code? Can I otherwise manipulate the tsquery data structure from PL/pgSQL without converting it to/from text? Would you recommend a different approach?

-Tobia

Browse pgsql-general by date

  From Date Subject
Next Message Oleg Bartunov 2016-06-17 13:47:08 Re: Question about RUM-index
Previous Message Vick Khera 2016-06-17 13:39:26 Re: Table ordering in pg_dump