views:

44

answers:

2

Is there any rule for the SQLite's column name?

  • Can it have characters like '/'?
  • Can it be UTF-8?
+3  A: 

http://www.sqlite.org/lang_keywords.html that has a complete list! enjoy!

Spooks
+1  A: 

Can it have characters like '/'?

All examples are from SQlite 3.5.9 running on Linux.

If you surround the column name in single quotes, you can:

> CREATE TABLE test_forward ( /test_column INTEGER );
SQL error: near "/": syntax error
> CREATE TABLE test_forward ('/test_column' INTEGER );
> INSERT INTO test_forward('/test_column') VALUES (1);
> SELECT test_forward.'/test_column' from test_forward;
1

EDIT: dan04 is right, if you do this you should probably used double quotes instead. That said, you probably shouldn't do this.

sheepsimulator
You can, but it will be a PITA for the rest of the life of the database. I would strongly recommend not doing it.
Brian Hooper
@Brian Hooper - I agree, but it actually sounds like putting single/double quotes is a good practice after reading http://www.sqlite.org/lang_keywords.html. I rarely see this in real-world queries, though.
sheepsimulator
I avoid using reserved words as table and column names. This can cause problems during migration and similar activities, but the number of reserved words isn't really very large and they can be avoided with a little thought. I prefer that to having to worry about those little ticks for the rest of my employment. But some code generators supply them automatically so it may not be an issue if you're using one of them.
Brian Hooper
Single quotes are for string literals. Double quotes are for identifiers. Single quotes work here because SQLite is liberal in what it accepts, but it's non-standard.
dan04