I'm creating a search inside a Rails app using the pg_search gem
. However, one of the tables have a Text
datatype field that it's content happens to be a little larger than usual.
Now when I need to setup a tsvector column
for the text
columns, I face some limitations that due the the text field size vs tsvector size.
ERROR: string is too long for tsvector (5068741 bytes, max 1048575 bytes)
Is there any way that I determine condition to skip bigger Text
fields while creating the tsvector column in the SQL
trigger to do something like this:
pseudocode:
execute(<<-TRIGGERSQL)
CREATE OR REPLACE FUNCTION public.essays_before_insert_update_row_tr()
RETURNS trigger
LANGUAGE plpgsql
AS $function$
BEGIN
If (SELECT LEN(body_text) FROM essays) <= 1048575
new.tsv_body_text := to_tsvector('pg_catalog.english', coalesce(new.body_text,''));
RETURN NEW;
End
END;
$function$
TRIGGERSQL
# no candidate create_trigger statement could be found, creating an adapter-specific one
execute("CREATE TRIGGER essays_before_insert_update_row_tr BEFORE INSERT OR UPDATE ON \"essays\" FOR EACH ROW EXECUTE PROCEDURE essays_before_insert_update_row_tr()")
related question that I found without an answer:
left
function. Isn't that function about getting as many characters from a text as specified? – Assyrian