ERROR: relation "table" does not exist, even though both the database and the table exist

ERROR: relation "table" does not exist, even though both the database and the table exist

我正在使用 cockroachdb,它本质上是 postgres 的超集,我无法理解为什么声明:

select * from _a66df261120b6c23.tabDefaultValue;

结果错误:

ERROR: relation "_a66df261120b6c23.tabdefaultvalue" does not exist

show databases 给我:

    database_name   | owner | primary_region | regions | survival_goal
--------------------+-------+----------------+---------+----------------
  _a66df261120b6c23 | root  | NULL           | {}      | NULL
  defaultdb         | root  | NULL           | {}      | NULL
  postgres          | root  | NULL           | {}      | NULL
  root              | root  | NULL           | {}      | NULL
  sammy             | root  | NULL           | {}      | NULL
  system            | node  | NULL           | {}      | NULL
  test123           | root  | NULL           | {}      | NULL
  test3             | root  | NULL           | {}      | NULL
  test4             | root  | NULL           | {}      | NULL
  test5             | root  | NULL           | {}      | NULL
  test9             | root  | NULL           | {}      | NULL

show tables from _a66df261120b6c23 给我:

  schema_name |    table_name     | type  | owner | estimated_row_count | locality
--------------+-------------------+-------+-------+---------------------+-----------
  public      | __Auth            | table | root  |                   0 | NULL
  public      | tabDefaultValue   | table | root  |                   0 | NULL

数据库和table都存在,为什么select * from _a66df261120b6c23.tabDefaultValue;会失败?奇怪的是当我 运行 \dt 我得到的是:

  schema_name | table_name | type  | owner | estimated_row_count | locality
--------------+------------+-------+-------+---------------------+-----------
  public      | sammy      | table | root  |                   0 | NULL

如何让 select 语句生效?谢谢

SQL 语句区分大小写,传入标识符小写,除非明确 forced with double quotes.

这意味着要引用您的tabDefaultValue,您需要使用以下语句:

select * from _a66df261120b6c23."tabDefaultValue";

请注意,引号仅包含 table 名称,如果将 dbname.tablename 引在一起,这将被视为中间带有一个点的单个标识符。