Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite issue with Table Names using numbers?

I'm developing an app which requires that the user selects a year formatted like this 1992-1993 from a spinner. The tablename is also named 1992-1993 and the idea is that using SQL the values from this table are pulled through with a statement like this select * from 1992-1993. When I run the emulator however, it throws an error.

If I then relabel the Spinner item to NinetyTwo and rename the table to NinetyTwo and run the emulator it runs as expected and the data is pulled through from the table.

Does SQLite have an issue with numbers in table names?

like image 626
Sumino7 Avatar asked Oct 24 '10 10:10

Sumino7


People also ask

Can SQLite table names have numbers?

Yes and No. It has an issue with numbers at the beginning of a table name. 1992-1993 is an expression returning -1 . Try to rename the table to Year1992 .

Can we use numbers in table name in SQL?

It's clear that you can use numeric characters in SQL table names and use them so long as they're not at the beginning.

Can table names have numbers?

The answer is yes, as given by karim79, as long as you take care to quote the table names. You could of course use a prefix with a numer, eg. mytable1, mytable2, ... ; that would work without quoting. That said, you should really think about why you want to create so many tables.

How do you name a table in SQLite?

To rename a table, the SQLite ALTER TABLE syntax is: ALTER TABLE table_name RENAME TO new_table_name; table_name. The table to rename.


1 Answers

Yes and No. It has an issue with numbers at the beginning of a table name. 1992-1993 is an expression returning -1. Try to rename the table to Year1992.

Here a similar issue on SO.

like image 72
eumiro Avatar answered Sep 22 '22 11:09

eumiro