Copy a table from one database to another in Postgres

前端 未结 19 1275
慢半拍i
慢半拍i 2020-11-28 00:21

I am trying to copy an entire table from one database to another in Postgres. Any suggestions?

19条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 01:10

    I tried some of the solutions here and they were really helpful. In my experience best solution is to use psql command line, but sometimes i don't feel like using psql command line. So here is another solution for pgAdminIII

    create table table1 as(
     select t1.* 
     from dblink(
       'dbname=dbSource user=user1 password=passwordUser1',
       'select * from table1'  
      ) as t1(
        fieldName1 as bigserial,
        fieldName2 as text,
        fieldName3 as double precision 
      )
     )
    

    The problem with this method is that the name of the fields and their types of the table you want to copy must be written.

提交回复
热议问题