I am looking to perform some database operations programatically inside a Django application, namely, I want to:
- Copy Table A in Database A over to Table A (table name preserved) in Database B, then clean-up and remove Table A.
Therefore, I have a number of possible options to try and utilise:
- I could try and call "pgdump" from the application, using some sort of system call.
- I could potentially utilise the
psycopg
package. - I have a preference to use Django's built in
with connection.cursor() as cursor
Assumptions:
- "Table A" exists in Database A but "Table A" (both schema and data) does not exist in Database B.
- Database A and Database B exist on different "HOSTs"
What would be the some potential methods to achieve this? I need something like this but to talk between the two databases, source and target...
CREATE TABLE [Table to copy To]
AS [Table to copy From]
WITH NO DATA;