10
6

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で曜日名をcase文使わずに1文で抽出する方法

Last updated at Posted at 2019-01-24

case文の場合

SELECT
  case EXTRACT(DOW FROM CAST('2019/01/24' AS DATE))
    when 0 then '日'
    when 1 then '月'
    when 2 then '火'
    when 3 then '水'
    when 4 then '木' 
    when 5 then '金' 
    when 6 then '土'
  end 

case文を使わない方法

arrayを使うと1文で書けます(※arrayの添字が1から始まるので要注意)

SELECT
  (array['日','月','火','水','木','金','土'])[EXTRACT(DOW FROM CAST('2019/01/24' AS DATE)) + 1]
10
6
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
10
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?