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 3 years have passed since last update.

postgresでselectで得た結果をカンマ区切り文字列にして1行で取得したい

Posted at

題の通りの備忘録

fruitというテーブルがあるとして
image.png

これを、「りんご,すいか,みかん,もも」という文字列で得たい。

select
    array_to_string(
        array(
            select fruit.fruit_name
            from fruit
            order by fruit.id
        ),
    ',');

見ての通り配列にしてからカンマ区切り文字列に直してます。

取得結果
image.png

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?