Re: pg_table_size errors "invalid name syntax" for table names containing spaces - Mailing list pgsql-bugs

From Tom Lane
Subject Re: pg_table_size errors "invalid name syntax" for table names containing spaces
Date
Msg-id 1558160.1623332617@sss.pgh.pa.us
Whole thread Raw
In response to Re: pg_table_size errors "invalid name syntax" for table names containing spaces  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: pg_table_size errors "invalid name syntax" for table names containing spaces
List pgsql-bugs
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Thursday, June 10, 2021, Michel Helms <michel@togetherdb.com> wrote:
>> CREATE TABLE "wei rd" (id SERIAL);
>> SELECT pg_table_size('wei rd');

> You still have to double-quote the name even if its being passed around in
> a string literal.

Yeah.  The reason for this is that you're also allowed to write qualified
table names:

SELECT pg_table_size('myschema.mytable');

That would seem to introduce an ambiguity: is the dot a schema separator,
or just an ordinary character (in a table name that was presumably written
with double quotes originally)?  We resolve this by saying that the
parsing rules for regclass_in are the same as they are in SQL text,
so you have to double-quote anything that is not a plain identifier
or needs to be protected against case-folding.

Hence, you should write

SELECT pg_table_size('"wei rd"');

            regards, tom lane



pgsql-bugs by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: pg_table_size errors "invalid name syntax" for table names containing spaces
Next
From: PG Bug reporting form
Date:
Subject: BUG #17056: Segmentation fault on altering the type of the foreign table column with a default