简体   繁体   English

如何从 Postgresql 中的特定数据库模式中删除表?

[英]How to DROP tables from specific database-schema in Postgresql?

I am new to Postgresql and so far I have not found a way to drop a table from specific database.我是 Postgresql 的新手,到目前为止我还没有找到从特定数据库中删除表的方法。 To give some context:给出一些背景:

We are doing a synchronization from Oracle to PostgreSQL of 5 tables.我们正在对 5 个表的 Oracle 到 PostgreSQL 进行同步。 In postgres I have a database SoloCopy and the schema is the default public .在 postgres 我有一个数据库SoloCopy并且架构是默认的public In the Postgresql instance we have also 2 more databases SoloSynch and postgres (the default one).在 Postgresql 实例中,我们还有另外 2 个数据库SoloSynchpostgres (默认数据库)。

What I want to do is to select SoloCopy database and:我想要做的是 select SoloCopy数据库和:

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.当我执行上述DROP语句时,表 1 仅从打开 SQL 查询时选择的数据库中删除。 But I want to specify the database before that and to be irrelevant from where the SQL Query was open.但我想在此之前指定数据库,并且与 SQL 查询的打开位置无关。 How can I do that?我怎样才能做到这一点?

I found an answer on my own.我自己找到了答案。 Setup can be found here: Psql in Task Scheduler does not run a file script可以在此处找到设置: 任务计划程序中的 Psql 不运行文件脚本

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.基本上我需要使用PSQL并使用连接字符串连接到一个特定的数据库,我可以从中删除表。 The details for PGPASSWORD and the .bat file I ended up creating are in the link above.我最终创建的PGPASSWORD.bat文件的详细信息在上面的链接中。 Had to start everything from CMD and switch to psql from there.必须从CMD开始一切,然后从那里切换到psql

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM