Postgres: Table names with spaces.

[expired user #8249]'s profile image [expired user #8249] posted 10 years ago in General Permalink
I created a new table in the public schema using a create table tableName as ...
Fine, however I had used a space instead of an underscore in the name.
The next time I connected to the database, it gave an 'Invalid name syntax' message with nothing shown in the public schema.
Opened in PGAdminIII no error and everything looked fine. I dropped the table with the space from PGAdmin and back in Heidi everything back to normal.
This did puzzle me for some hours.

Code modification/commit from ansgar.becker, 10 years ago, revision 8.3.0.4821
Quote schema and table name in TPGConnection.FetchDbObjects. Fixes empty tables list. See http://www.heidisql.com/forum.php?t=16429
ansgar's profile image ansgar posted 10 years ago Permalink
r4821 fixes that. The problem was the unquoted schema and table name in this query:
SELECT *, pg_table_size(t.TABLE_SCHEMA || '.' || t.TABLE_NAME) AS data_length, pg_relation_size(t.TABLE_SCHEMA || '.' || t.TABLE_NAME) AS index_length, c.reltuples, obj_description(c.oid) AS comment FROM "information_schema"."tables" ...

With my fix in r4821, HeidiSQL applies QUOTE_IDENT() on the schema and table names on PostgreSQL 7.3 and up, and does a manual quoting on older servers:
SELECT *, pg_table_size(QUOTE_IDENT(t.TABLE_SCHEMA) || '.' || QUOTE_IDENT(t.TABLE_NAME)) AS data_length, pg_relation_size(QUOTE_IDENT(t.TABLE_SCHEMA) || '.' || QUOTE_IDENT(t.TABLE_NAME)) AS index_length, c.reltuples, obj_description(c.oid) AS comment FROM "information_schema"."tables" ...

Please login to leave a reply, or register at first.