Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 幻影Postgres表存在,但可以';不能放弃吗?_Postgresql - Fatal编程技术网

Postgresql 幻影Postgres表存在,但可以';不能放弃吗?

Postgresql 幻影Postgres表存在,但可以';不能放弃吗?,postgresql,Postgresql,我似乎在研究生中有某种幻觉表 假设我执行以下操作: select * from information_schema.tables where table_schema = 'public'; 我得到: table_name | table_type | ... phantom_table BASE TABLE ... 因此,我运行: drop table phantom_table cascade; 我得到: ERROR: table "phantom_table" doe

我似乎在研究生中有某种幻觉表

假设我执行以下操作:

select * from information_schema.tables where table_schema = 'public';
我得到:

table_name     | table_type | ...
phantom_table    BASE TABLE
...
因此,我运行:

drop table phantom_table cascade;
我得到:

ERROR: table "phantom_table" does not exist
我尝试过的事情:

  • 检查拼写错误并确保模式正确(我甚至从信息模式查询结果中复制/粘贴了表名)
  • vacuum
  • 重新连接
  • 从我的用户那里杀死其他正在运行的进程(没有其他人在使用数据库)
  • 正在检查表上的活动锁(没有)

  • 有人对我应该尝试的东西有什么其他想法吗?

    你可能在名字的末尾有一些空白

    最简单的方法是让
    format()
    函数生成正确的表名和语句:

    select format('drop table %I.%I;', table_schema, table_name) as drop_statement
    from information_schema.tables 
    where table_schema = 'public'
      and table_name like '%phantom%';
    
    Edit:Windows上的
    psql
    似乎无法在
    drop
    语句中使用新行处理标识符(但是在创建表时会这样做)

    要解决此问题,可以使用DO块:

    do
    $$
    declare
     l_stmt text;
    begin
      select format('drop table %I.%I;', table_schema, table_name) as drop_statement
        into l_stmt
      from information_schema.tables 
      where table_schema = 'public'
        and table_name like '%phantom%';
      execute l_stmt;    
    end;
    $$
    ;
    

    注意:此代码假定只有一个具有该名称的表存在

    名称末尾可能有一些空白

    最简单的方法是让
    format()
    函数生成正确的表名和语句:

    select format('drop table %I.%I;', table_schema, table_name) as drop_statement
    from information_schema.tables 
    where table_schema = 'public'
      and table_name like '%phantom%';
    
    Edit:Windows上的
    psql
    似乎无法在
    drop
    语句中使用新行处理标识符(但是在创建表时会这样做)

    要解决此问题,可以使用DO块:

    do
    $$
    declare
     l_stmt text;
    begin
      select format('drop table %I.%I;', table_schema, table_name) as drop_statement
        into l_stmt
      from information_schema.tables 
      where table_schema = 'public'
        and table_name like '%phantom%';
      execute l_stmt;    
    end;
    $$
    ;
    

    注意:此代码假定只有一个具有该名称的表存在

    有趣的。。。我得到的drop语句在表名中确实有一个换行符,但该语句仍然没有运行。@JohnChrysostom:那么名称中确实有一些空白。但是生成的语句应该能够处理这个问题。无法使生成的语句工作-我怀疑我在与Windows/Unix断线差异作斗争。使用此函数的修改版本可以完成此操作,不过。。。谢谢你的帮助。很有趣。。。我得到的drop语句在表名中确实有一个换行符,但该语句仍然没有运行。@JohnChrysostom:那么名称中确实有一些空白。但是生成的语句应该能够处理这个问题。无法使生成的语句工作-我怀疑我在与Windows/Unix断线差异作斗争。使用此函数的修改版本可以完成此操作,不过。。。谢谢你的帮助。