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 1 year has passed since last update.

PostgreSQLでIntegerからEnumへ変換(キャスト)する方法

Last updated at Posted at 2023-04-18

前提

以下のenumが定義されている

CREATE TYPE fruits AS ENUM ('リンゴ',
    'バナナ',
    'みかん',
    'いちご');

IntegerからEnumへ

SELECT (ENUM_RANGE(NULL::fruits))[1];
# りんご

SELECT (ENUM_RANGE(NULL::fruits))[2];
# バナナ

SELECT (ENUM_RANGE(NULL::fruits))[3];
# みかん

SELECT (ENUM_RANGE(NULL::fruits))[4];
# いちご
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?