LoginSignup
2
0

More than 1 year has passed since last update.

postgres 公式参照 like

Last updated at Posted at 2019-01-25
SELECT
 first_name,
 last_name
FROM
 customer
WHERE
 first_name LIKE 'Jen%'
first_name last_name
Jennifer Davis
Jennie Terry
Jenny Castro
SELECT
 'foo' LIKE 'foo', -- true
 'foo' LIKE 'f%', -- true
 'foo' LIKE '_o_', -- true
 'bar' LIKE 'b_'; -- false

こういう使い方もできるそうです

true true true false

not likeもあり、結果が逆になります。

~~はと同等です LIKE
~~ *はと同等です ILIKE
!~~はと同等です NOT LIKE
!~~ *はと同等です NOT ILIKE

SELECT
 'foo' ~~ 'foo', -- true
 'foo' ~~ 'f%', -- true
 'foo' ~~ '_o_', -- true
 'bar' ~~ 'b_'; -- false
true true true false

ILIKEを使うと、大文字、小文字を区別しないそうです。

PostgreSQLはILIKE演算子のように振舞う演算子を提供しますLIKE。さらに、ILIKE演算子は値を大文字と小文字を区別せずに照合します。次の例を見てください。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0