Trouble with text search select statement

From: "Mont Rothstein" <mont(dot)rothstein(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Trouble with text search select statement
Date: 2008-04-30 23:41:10
Message-ID: 467a83630804301641o5985186n4151e0f44a427e43@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am having trouble getting a multiple column text search select statement
to work.

I've setup the following:

CREATE TABLE tstest (col1 text, col2 text);
INSERT INTO tstest (col1, col2) VALUES ('bird', 'moon');
CREATE INDEX tstest_ts_idx ON tstest USING gin(to_tsvector('english',
coalesce(col1, '') || '' || coalesce(col2, '')));

I then execute what I believe is the correct select statement:

SELECT * FROM tstest WHERE to_tsvector('english', coalesce(col1, '') || ''
|| coalesce(col2, '')) @@ to_tsquery('english', 'bird');

If I remove the second column from the to_tsvector in the select statement
then it returns the row.

SELECT * FROM tstest WHERE to_tsvector('english', coalesce(col1, '')) @@
to_tsquery('english', 'bird');

I know I've missed something basic but I can't figure out what.

As a side note I don't understand the purpose of the || '' || between the
columns in the to_tsvector. I saw it in several examples. I've tried both
with and without it with no change.

Thanks in advance.

-Mont

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Klint Gore 2008-05-01 02:45:41 Re: Trouble with text search select statement
Previous Message Alvaro Herrera 2008-04-30 22:04:28 Re: Backslash Escape Sequences