Emanuele Mazzoni
Emanuele Mazzoni

Reputation: 716

Select only specific results in sql (postgresql)

SELECT id, name::tsvector @@ 'substring1 & substring2'::tsquery
FROM table

I have this. The result of this query has 2 fields: id, ?column? The ?column? field value is true or false. how can I get only the true results?

Upvotes: 0

Views: 131

Answers (4)

Wldmr
Wldmr

Reputation: 1

use alias to reference your column

SELECT id, name::tsvector @@ 'substring1 & substring2'::tsquery AS condition
FROM table
WHERE condition = true

Upvotes: 0

fuzzyalej
fuzzyalej

Reputation: 5973

SELECT * FROM (
  SELECT id, name::tsvector @@ 'substring1 & substring2'::tsquery
  FROM table
) AS search
WHERE column = 't'

You can also use WITH: http://www.postgresql.org/docs/9.1/static/queries-with.html

Upvotes: 1

amelian
amelian

Reputation: 446

Add a WHERE clausure to fill this values. Something like this.

SELECT id, name::tsvector @@ 'substring1 & substring2'::tsquery FROM table WHERE ?column? = 1 (or True)

Upvotes: 0

Dani
Dani

Reputation: 15069

use WHERE clause.... (if i understand your need correctly)

WHERE condition = true

Upvotes: 0

Related Questions