【问题标题】:ERROR: relation "table" does not exist, even though both the database and the table exist错误:关系“表”不存在,即使数据库和表都存在
【发布时间】:2021-09-02 04:24:07
【问题描述】:

我正在使用 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

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

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

如何让select 语句真正起作用?谢谢

【问题讨论】:

    标签: cockroachdb


    【解决方案1】:

    SQL 语句区分大小写,传入的标识符是小写的,除非特别是 forced with double quotes

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

    select * from _a66df261120b6c23."tabDefaultValue";
    

    请注意,引号仅围绕表名,如果您将dbname.tablename 一起引用,这将被视为中间带点的单个标识符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-11
      • 1970-01-01
      • 2016-04-30
      • 2014-12-25
      相关资源
      最近更新 更多