Does SQLite support common table expressions?

我们两清 提交于 2020-01-02 04:41:28

问题


Does SQLite support common table expressions?

I'd like to run query like that:

with temp (ID, Path) 
as (
  select ID, Path from Messages
) select * from temp

回答1:


As of Sqlite version 3.8.3 SQLite supports common table expressions.

Change log

Instructions




回答2:


Another solution is to integrate a "CTE to SQLite" translation layer in your application :

"with w as (y) z" => "create temp view w as y;z"

"with w(x) as (y) z" => "create temp table w(x);insert into w y;z"

As an (ugly, desesperate, but working) example : http://nbviewer.ipython.org/github/stonebig/baresql/blob/master/examples/baresql_with_cte_code_included.ipynb




回答3:


SQLite doesn't support CTEs, window functions, or any of the like. You can, however, write your own user functions that you can call inside SQLite by registering them to the database with the SQLite API using sqlite_create_function(). You register them with the database, and then you can use them in your own application code. You can make an aggregate function that would perform the sum of a series of averages based on the individual column values. For each value, a step-type callback function is called that allows you to perform some calculation on the data, and a pointer for holding state data is also available.



来源:https://stackoverflow.com/questions/18593068/does-sqlite-support-common-table-expressions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!