Search Postgresql Archives

Re: Like operator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux