Re: Like operator - Mailing list pgsql-general

From Richard Huxton
Subject Re: Like operator
Date
Msg-id 4666C04E.5070807@archonet.com
Whole thread Raw
In response to Like operator  ("rupesh bajaj" <rupesh.bajaj@gmail.com>)
List pgsql-general
rupesh bajaj wrote:
> Hi,
> Is Like operator can be used to join two relation. If yes what is its use?
> And how it is used?

It tests a column for a partial match. So:

'abc' LIKE 'a%' = true
'abc' LIKE 'a_c' = true
'abc' LIKE 'A%' = false

See the manuals for details on other wildcard options and alternative
pattern-matching systems.

You can store the pattern in a column too, though that's less common:

richardh=> SELECT * FROM targets;
     tgt
-----------
  abc123def
  ghi123def
(2 rows)

richardh=> SELECT * FROM patterns;
  patt
-------
  abc%
  %123%
(2 rows)

richardh=> SELECT tgt,count(*) FROM targets, patterns
WHERE tgt LIKE patt GROUP BY tgt ORDER BY tgt;
     tgt    | count
-----------+-------
  abc123def |     2
  ghi123def |     1
(2 rows)

HTH
--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: plperl and/or insert trigger problem
Next
From: "Bart Degryse"
Date:
Subject: Re: plperl and/or insert trigger problem