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

后端 未结 5 1888
渐次进展
渐次进展 2021-01-01 05:54

(sorry for my poor english)

If you try this select operation over a sqlite database:

SELECT column AS \'alias 1\' FROM table;

相关标签:
5条回答
  • 2021-01-01 06:07

    If you're using the SQLite 3 then the following query works just fine with various types used for the Alias column names.

    See the result below the query:

    select '1' as 'my.Col1', '2' as "my.Col2", '3' as [my.Col3], '4' as [my Col4] , '5' as 'my Col5' 
    

    enter image description here

    0 讨论(0)
  • 2021-01-01 06:07

    I've found a "fix"...

    SELECT column AS '.alias.1' FROM table;

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

    just another dot in the begining...

    of course I don't like this solution... any other idea??

    0 讨论(0)
  • 2021-01-01 06:19

    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

    0 讨论(0)
  • 2021-01-01 06:21

    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

    0 讨论(0)
  • 2021-01-01 06:23

    Definitely working properly:

    C:\Windows>sqlite3.exe
    SQLite version 3.7.8 2011-09-19 14:49:19
    Enter ".help" for instructions
    Enter SQL statements terminated with a ";"
    sqlite> .mode column
    sqlite> .headers on
    sqlite> SELECT 'hello' AS 'alias.1';
    alias.1
    ----------
    hello
    sqlite>
    
    0 讨论(0)
提交回复
热议问题