postgresql: INSERT INTO … (SELECT * …)

前端 未结 6 1440
醉话见心
醉话见心 2020-12-04 08:49

I\'m not sure if its standard SQL:

 INSERT INTO tblA 
 (SELECT id, time 
    FROM tblB 
   WHERE time > 1000)  

What I\'m looking for

6条回答
  •  无人及你
    2020-12-04 09:36

    Here's an alternate solution, without using dblink.

    Suppose B represents the source database and A represents the target database: Then,

    1. Copy table from source DB to target DB:

      pg_dump -t   | psql 
      
    2. Open psql prompt, connect to target_db, and use a simple insert:

      psql
      # \c ;
      # INSERT INTO (id, x, y) SELECT id, x, y FROM ;
      
    3. At the end, delete the copy of source_table that you created in target_table.

      # DROP TABLE ;
      

提交回复
热议问题