1

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?

3
  • 1
    Does this answer help you? Commented Aug 9, 2022 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... Commented Aug 9, 2022 at 13:56
  • - you can make cross-database queries if you want do it in pgAdmin 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...) Commented Aug 9, 2022 at 14:06

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.