postgresql - 在 bash 中使用 psql 命令查询 postgresql 抛出错误 : relation "testschema.testtable" does not exist

标签 postgresql psql

在 bash 中运行以下命令会抛出:

ERROR: relation "testschema.testtable" does not exist.

命令行:

psql -h "localhost" -d "postgres" -U "postgres" -c "select * from TestSchema.TestTable;"

为什么搜索关系而不是模式? 如何设置要搜索的默认模式,以及是否可以将来自多个数据库的多个模式的列表设置为默认列表?

最佳答案

Why is it searching relation rather than schema?

TestSchema.TestTable 一个关系(表)。 I 是完全限定的表名。

它找不到它的原因很可能是因为您使用双引号创建了模式和表:

create table "TestSchema"."TestTable" (...)

这使得名称区分大小写并强制您始终使用引号来限定名称。有关“定界标识符”(又名“带引号的标识符”)的详细信息,请参阅手册:

https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

How can I set default schema to be searched

请参阅“设置模式”语句:https://www.postgresql.org/docs/current/sql-set.html

您还可以使用 ALTER USER 命令定义默认模式。

can I set a list of multiple schemas from multiple databases as default list

是的,设置search_path配置变量:http://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-SEARCH-PATH

这也可以通过 ALTER USER 语句永久设置。

关于postgresql - 在 bash 中使用 psql 命令查询 postgresql 抛出错误 : relation "testschema.testtable" does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15051022/

相关文章:

sql - 如何将 PostgreSQL 输出保存到文本文件

ruby-on-rails - Rails/Postgres 连接问题(psql 和 pg 工作正常)

ruby-on-rails - 无法识别 'location' 的类型。它将被视为 String

sql - 获取 postgresql 中有序集合的最后一个元素

javascript - 从 postgres 函数运行 python 或 javascript 文件?

postgresql - 使用没有密码的 psql 命令运行批处理文件

postgresql - psql:致命:用户 ""aws rds Postgresql 的 PAM 身份验证失败

postgresql - 按回车键后如何在 SQL cli 中编辑输入?

sql - Postgres 跳过选择中的重复字段

ruby-on-rails - simple_form 未找到 json 的输入