SQLite Forum

quoted table name after table rename
Login

quoted table name after table rename

(1) By anonymous on 2022-09-08 19:01:19 [link] [source]

I noticed that after renaming a table the new table name is quoted. Is that just an artifact to be ignored? Or perhaps it's a version thing?

Thanks.

sqlite> create table t (foo); sqlite> select * from sqlite_master; table|t|t|2|CREATE TABLE t (foo) sqlite> alter table t rename to x; sqlite> select * from sqlite_master; table|x|x|2|CREATE TABLE "x" (foo)

(2) By Donald Griggs (dfgriggs) on 2022-09-08 19:34:29 in reply to 1 [source]

You'll want to ignore it.

In the general case, double quotes (or, less preferred, square brackets or backticks) would be required.

Most commonly it would be required when spaces are in the table name, but all sorts of hideous things can be part of a table name if you're determined, such as:

CREATE TABLE "This is a <bad name> for a table; don't you think?" (c1 TEXT);

So you can see why sqlite would always include the quotes.

(3) By anonymous on 2022-09-10 02:45:35 in reply to 2 [link] [source]

Fair enough. But my comment was mainly about the difference between the initial able create (which shows the table name without quotes) and after the alter table (which shows the table name with quotes).

That part still seems odd.

But thanks.

(4) By Stephan Beal (stephan) on 2022-09-10 03:07:39 in reply to 3 [link] [source]

But my comment was mainly about the difference between the initial able create

Try again with a quoted table name in the initial create.

That part still seems odd.

It's consistent with how sqlite will rename tables, just not consistent with how you typed in the initial name. sqlite cannot reasonably be expected to look at the schema's raw-text name and duplicate the quoting used (or not used) in the initial declaration.

(5) By Chris Locke (chrisjlocke1) on 2022-09-10 07:33:07 in reply to 3 [link] [source]

difference between the initial able create (which shows the table name without quotes)

This is because SQLite doesn't amend what the user types in. If the initial create is put in with quotes, then SQLite stores it with quotes. The initial table name was put in by the user.

When SQLite itself creates a table (ie, during the rename operation), it uses quotes.