2
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.

SELECT文でのVALUE句

Last updated at Posted at 2022-07-01

最近Treasure Dataでクエリを書いていて、INSERT文ではなくSELECT文でVALUE句を使用できると学んだので、備忘録として記載します。

SELECT
  *
FROM
  (VALUES
    (1, 'AAA')
   , (2, 'BBB')
   , (3, 'CCC')
 ) AS usersid, name)

実行結果は下記の通りです。

id name
1 AAA
2 BBB
3 CCC

ASのエイリアス部分は

AS table_name(column1, column2...)

という風になっています。
なのでSELECT文を使用して、CREATEとINSERTを同時に行い、一時的にテーブルを作成するといったイメージでしょうか。

参考

https://www.postgresql.jp/document/9.6/html/queries-values.html
https://qiita.com/D-Three/items/62db5e03b9425f1ecb25
https://qiita.com/tiechel/items/f86f13f63feb3433e97c

2
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
2
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?