Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlite: alias column name can't contains a dot "."

Tags:

sql

sqlite

(sorry for my poor english)

If you try this select operation over a sqlite database:

SELECT column AS 'alias 1' FROM table;

You get the expected column name:

alias 1
--------
result 1
result 2

but if your alias contains a dot "." ... you get a wrong column name:

SELECT column AS 'alias.1' FROM table;

1
--------
result 1
result 2

(all behind the dot is ommited in the column name)

Wow... It's weird...

anyone can help me?

thank you very much

UPDATE:

maybe it's just a bug in SQLiteStudio (the software where I'm testing my queries) and in QT (they both doesn't expect dots in alias names but sqlite does)

like image 769
Javi Moya Avatar asked Mar 07 '11 22:03

Javi Moya


People also ask

How do you select a column from SQL with a dot in its name?

Use backticks around the column name User. FirstName. LastName which contains (.).

Can SQLite column names have spaces?

Blanks spaces are restricted in the naming convention of the database object's name and column name of the table.

Does SQLite support aliases?

You can rename a table or a column temporarily by giving another name, which is known as ALIAS. The use of table aliases means to rename a table in a particular SQLite statement.

Can column name have space?

To select a column name with spaces, use the back tick symbol with column name. The symbol is ( ` `).


2 Answers

Enclose your alias in double quotes.

SELECT 'test' AS "testing.this"

Output:

| testing.this |
  test

Updated: Double quotes are used to enclose identifiers in SQL, not single quotes. Single quotes are only for strings. In this case you are trying to ensure that "testing.this" is used as is and not confused as testing.this (testing table this column).

http://www.sqlite.org/faq.html#q24

like image 200
Kevin Peno Avatar answered Sep 26 '22 15:09

Kevin Peno


Use backticks

SELECT column AS `alias.1` FROM table;

Or double quotes (ANSI standard) per the other answer

SELECT column AS "alias.1" FROM table;

Both verified in SQLite Manager for FireFox

like image 24
RichardTheKiwi Avatar answered Sep 24 '22 15:09

RichardTheKiwi