Search code examples
sqlpostgresqldrop-table

Delete table with empty name in PostgreSQL


I'm trying to remove one of my tables stored in PostgreSQL 8.3.8 32bit.

Strange is that my table doesn't have a name, it's empty. Where I do:

SELECT * FORM pg_catalog.pg_tables;

it says that me tablename name is null. When I try to delete my table:

DROP TABLE sde. ;

where sde is my schemaname, error appears, telling me that there is a syntax error.

ERROR: syntax error at or near ";"
LINE 1:drop table sde. ;

Is there any way to delete that table?

I also tried that

DROP TABLE sde.'';

But still error appears.

My table has OID. Is it possible to delete it by OID?

The best solution for me would be renaming that table, that I can save my data from that table.


Solution

  • You cannot create table with empty name:

    tgr=# create table "" ();
    ERROR:  zero-length delimited identifier at or near """"
    LINE 1: create table "" ();
    

    However you can create a table with a lot of spaces, including newlines:

    create table "               
    
                       " ();
    

    To work with such table:

    1. Find it in information_schema.tables
    2. Copy/paste table name in some command in double quotes ("")

    When the previous fails, you can try to update pg_class directly. If you have table OID, try this:

    update pg_class set relname = 'test'::name where oid = <<YourOID>>;