在 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/