问题
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
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?
Edit Until 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.
回答1:
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
来源:https://stackoverflow.com/questions/52954732/sqlite-generate-series-missing