LoginSignup
22
16

More than 5 years have passed since last update.

【備忘録】PostgreSQLでselectした結果をinsertするSQL

Posted at

いつも忘れてしまうのでメモ。

PostgreSQLで、selectした結果をそのまま他テーブルにinsertする方法のSQL。
いつもの insert 文の後に select 文をくっつけるだけでいい。

というわけでSQLのサンプル。

insert into 宛先テーブル
(
    column1,
    column2,
    column3
)
select
    column1,
    column2,
    column3
from
    移行元テーブル
where
    column3 >= 100
22
16
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
22
16