【问题标题】:How to switch databases in postgres?如何在 postgres 中切换数据库?
【发布时间】:2018-10-07 22:30:57
【问题描述】:

在 SQL Server 中,我使用:

 use database_name
 Go
 Select * from table_name

在postgreSQL中,我仍然使用:

 \connect database_name
 Select * from table_name
========================
then error: 
ERROR:  syntax error at or near "\"
LINE 1: \connect database_name
        ^
********** Error **********

ERROR: syntax error at or near "\"
SQL state: 42601
Character: 1.

为什么? 可以帮我吗?谢谢。

【问题讨论】:

  • 使用 PgAdmin - III 调用命令。
  • 出现错误是因为 psql CLI 中的每个命令都必须以 ";" 终止因此,只需执行 \connect database_name;然后,select * from table_name;

标签: postgresql


【解决方案1】:

从技术上讲,PostgreSQL 不能切换数据库。您必须断开连接并重新连接到新数据库。

psql 命令行客户端将使用\connect 命令、快捷方式\c 为您执行此操作。但这些不是 PostgreSQL 服务器处理的命令,它们是客户端命令。不同的客户不会理解或支持他们。

猜测您正在使用 PgAdmin-III,在这种情况下 use the pulldown menu in the query tool to switch databases

有一天,我想将psql 的反斜杠命令代码提取到 PgAdmin 之类的东西也可以链接到并使用的库中。

【讨论】:

  • 谢谢。有帮助。
猜你喜欢
  • 2012-04-19
  • 2022-01-15
  • 2011-04-26
  • 1970-01-01
  • 1970-01-01
  • 2012-08-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多