Syntax error in tsquery: parameter with spaces

I have a full text search function:

CREATE OR REPLACE FUNCTION search_questions(psearch text)
  RETURNS TABLE (questionid INTEGER) AS $func$
BEGIN
  return QUERY
  SELECT DISTINCT (questions.publicationid)
  FROM questions
  WHERE to_tsvector(coalesce(questions.title, '')) @@ to_tsquery(psearch)
        OR
        publicationid IN (
          SELECT DISTINCT(publications.publicationid) FROM publications WHERE to_tsvector(coalesce(publications.body, '')) @@ to_tsquery(psearch)
        )
  ;
END
$func$  LANGUAGE plpgsql;

      

but it only works with one word parameter. If I search for "custom test" it returns

ERROR: syntax error in tsquery: "user test"

Is there a way to search for texts with spaces in it?

respectfully

+3


source to share


2 answers


I found how to solve it. Here it goes

Replace: to_tsquery(psearch)



from: plainto_tsquery(psearch)

+6


source


You can put single quotes around your terms and still use to_tsquery()

.



+1


source







All Articles