SQLite转换AS:SQLite v2.8.17的语法错误

时间:2017-11-01 23:08:04

标签: sqlite casting

我明白了:

$ echo "SELECT cast((strftime('%s','2017-11-01 22:25:28')-strftime('%s','2017-10-15 12:40:28')) AS real)/60/60 AS elapsed_hours;" | sqlite
SELECT cast((strftime('%s','2017-11-01 22:25:28')-strftime('%s','2017-10-15 12:40:28')) AS real)/60/60 AS elapsed_hours;
SQL error: near "AS": syntax error

$ sqlite
SQLite version 2.8.17
Enter ".help" for instructions
sqlite> SELECT cast((strftime('%s','2017-11-01 22:25:28')-strftime('%s','2017-10-15 12:40:28')) AS real)/60/60 AS elapsed_hours;
SQL error: near "AS": syntax error

然而,完全相同的SQL

SELECT cast((strftime('%s','2017-11-01 22:25:28')-strftime('%s','2017-10-15 12:40:28')) AS real)/60/60 AS elapsed_hours;

http://www.sqlitetutorial.net/tryit/query/sqlite-date/

上正常工作

怎么了?我的SQLite是:

$ apt-cache policy sqlite
sqlite:
  Installed: 2.8.17-14fakesync1
  Candidate: 2.8.17-14fakesync1
  Version table:
 *** 2.8.17-14fakesync1 500
        500 http://ca.archive.ubuntu.com/ubuntu zesty/universe amd64 Packages
        100 /var/lib/dpkg/status

THX

1 个答案:

答案 0 :(得分:0)

哦,谢谢@muistooshort,我认为我最新的ubuntu有最新的SQLite,

但经过调查后,我发现我应该安装/使用sqlite3而不是sqlite

$ apt-get install sqlite3 sqlite-