Postgres - CREATE TABLE FROM SELECT

前端 未结 2 732
庸人自扰
庸人自扰 2020-12-14 07:52

I have two tables, one contains a large list of IDs and Info regarding those ids.

I have a second table Graph which just has two columns, each column co

2条回答
  •  囚心锁ツ
    2020-12-14 08:18

    It's as easy as:

    create table new_table
    as 
    select t1.col1, t2.col2
    from some_table t1
       join t2 on t1.id = t2.some_id;
    

    You can use any select statement for that. The column names of the new table are defined by the column aliases used in th query.

    More details in the manual: http://www.postgresql.org/docs/current/static/sql-createtableas.html

提交回复
热议问题