sqlite:别名列名不能包含点“." [英] sqlite: alias column name can't contains a dot "."

查看:43
本文介绍了sqlite:别名列名不能包含点“."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(抱歉我的英语不好)

如果你在 sqlite 数据库上尝试这个选择操作:

If you try this select operation over a sqlite database:

SELECT column AS 'alias 1' FROM table;

SELECT column AS 'alias 1' FROM table;

您得到预期的列名:

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;

SELECT column AS 'alias.1' FROM table;

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

(列名中省略了点后面的所有内容)

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

哇...好奇怪……

有人可以帮我吗?

非常感谢

更新:

也许这只是 SQLiteStudio(我用来测试查询的软件)和 QT(他们都不希望别名中有点,但 sqlite 有)中的一个错误

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)

推荐答案

用双引号将别名引起来.

Enclose your alias in double quotes.

SELECT 'test' AS "testing.this"

输出:

| testing.this |
  test

更新:双引号用于将 SQL 中的标识符括起来,而不是单引号.单引号仅用于字符串.在这种情况下,您要确保testing.this"按原样使用,而不是与 testing.this(testingthis 列)混淆.

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

这篇关于sqlite:别名列名不能包含点“."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆