0

I am using COPY public.source TO STDOUT; It is copying table source from database foo and sending it to psql shell.

1   1   1
2   2   2
3   0   3
4   1   4
5   2   0
6   0   1
7   1   2
8   2   3
9   0   4
10  1   0

I want to copy all records from the same table source of database foo to table dest in database bar. Any idea how can I do it with query like COPY public.source TO <missing solution to copy data into bar.public.dest>;

Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160
  • 1
    I think it's better to do this in the shell and not with sql commands, see https://stackoverflow.com/questions/3195125/copy-a-table-from-one-database-to-another-in-postgres. – zwippie May 08 '20 at 13:07
  • I am also to remove [tag:elixir] tag since the question has nothing to do with [tag:elixir]. – Aleksei Matiushkin May 08 '20 at 13:19

1 Answers1

1

Here is answering the particular question about using COPY.

According to the documentation on PostgresSQL COPY,

COPY — copy data between a file and a table

which roughly means you are to do this in two steps: copy the existing data from source DB to file/stdin and then copy from file/stdin to destination DB.

Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160