问题描述
我正在尝试使用SQLite CLI,但无法获取 generate_series
功能正常工作.正如文档中所建议的,我可以使用递归CTE对其进行仿真,但似乎无法使该链接中的任何示例正常工作.这是我的会话的一些输出:
I'm trying to work with the SQLite CLI, and I can't get the generate_series
function to work. I can simulate it with the recursive CTE, as suggested in the documentation, but I can't seem to get any of the examples in that link to work. Here's some output from my session:
sqlite> with recursive generate_series(value) as (
select 1
union all select value+1
from generate_series
where value+1<=3)
select value from generate_series;
1
2
3
sqlite> select value from generate_series;
Error: no such table: generate_series
sqlite> select value from generate_series(1,3,1);
Error: no such table: generate_series
似乎ext/misc/series.c
扩展名实际上不是静态链接的.如果我从头开始编译,我也不知道该怎么做.我在这里做错什么了吗?
It seems like the ext/misc/series.c
extension is not actually being statically linked. I also don't know how to do that if I compile from scratch. Am I doing something wrong here?
修改直到如何将扩展编译为SQLite 有了一个很好的答案,我不要以为我能做我想做的事.文档是错误的:默认情况下,扩展名未内置到命令行外壳中.
EditUntil how to compile an extension into SQLite has a good answer, I don't think I'll be able to do what I want. The documentation is wrong: the extension is not build into the command line shell by default.
推荐答案
下载扩展程序: https://sqlite.org/src/file/ext/misc/series.c 并使用以下命令进行编译:
Download the extension: https://sqlite.org/src/file/ext/misc/series.c and compile it with:
gcc -g -O2 -shared -fPIC -o series ./series.c
在此之后,以下应该工作:
After this the following should be working:
$ sqlite3
sqlite> .load ./series
sqlite> select value from generate_series(5,30,5);
5
10
15
20
25
30
sqlite> .exit
这篇关于SQLite generate_series丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!