0
0

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.

【SQL】住所から都道府県だけ抽出する正規表現【PostgreSQL】

Last updated at Posted at 2019-12-04

カラムには市町村まで入っているが都道府県単位で集計したいときに便利

SELECT 
    SUBSTRING(table.city FROM '東京都|北海道|(?:京都|大阪)府|.{2,3}県') todouhuken
FROM table

正規表現自体はMysqlやBQとか(なんならプログラミング言語)でも使えるはずなので参考になれば幸いです。

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?