15
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PostgreSQLの同一カラムで部分一致検索を複数行う方法

Posted at

通常、部分一致の検索を複数行う場合には、以下のようにやるかと思います。

select * from hoge where name like 'uno%' or name like 'dos%';

ですが、カラムが同一であれば、以下のようにまとめることが出来ます。

select * from hoge where name ~~* any(array['uno%', 'dos%']);

更には、副問合せを使ってこんな風にすることも。

select * from hoge where name ~~* any(select name || '%' from fuga);

なかなか便利で、重宝します。

15
24
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
15
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?