0

I am new to Postgresql and so far I have not found a way to drop a table from specific database. To give some context:

We are doing a synchronization from Oracle to PostgreSQL of 5 tables. In postgres I have a database SoloCopy and the schema is the default public. In the Postgresql instance we have also 2 more databases SoloSynch and postgres (the default one).

What I want to do is to select SoloCopy database and:

DROP TABLE public.table1;

When I do the above DROP statement table1 is deleted only from the database that was selected when opening SQL Query. But I want to specify the database before that and to be irrelevant from where the SQL Query was open. How can I do that?

Braiam
  • 1
  • 11
  • 47
  • 78
DarkBlade
  • 47
  • 6
  • 1
    Does [this answer](https://stackoverflow.com/a/10338367) help you? – diiN__________ Aug 09 '22 at 12:03
  • No, unfortunately nothing from this topic helps me. I need to select a specific database before running the `DROP` statements. But pgAdmin opens the Query tool for a cpecific database and it does not seem like I can switch to another with code... – DarkBlade Aug 09 '22 at 13:56
  • - you can make cross-database queries if you want do it in pgAdmin https://fedingo.com/how-to-make-cross-database-queries-in-postgresql/ - if you want do it by code better solve its do it using different connections. (open connection and do query with this connection, and do same with another connection...) – defourten Aug 09 '22 at 14:06

1 Answers1

0

I found an answer on my own. Setup can be found here: Psql in Task Scheduler does not run a file script

Basically I needed to use PSQL and with the connection string there I connect to a specific DB, which I can drop the tables from. The details for PGPASSWORD and the .bat file I ended up creating are in the link above. Had to start everything from CMD and switch to psql from there.

DarkBlade
  • 47
  • 6