SQLite Forum

Reference to RECURSIVE table column apparently not allowed in nested SELECT
Login
Note that "constant scalar expression" means that the following is permitted:

select * from x limit (select x from x);

but the following is not:

select * from x as o limit (select x from x where x == o.x);

and indeed this is the case and the latter will produce the same error message "Error: no such column: o.x" when really the error message should be "Error: not a constant expression: o.x" (as the simplest form).  "Error:  LIMIT/OFFSET must be a constant expression" would also be satisfactory and accurate.

This means, of course, that things such as:

select * from here limit (select pagesize from config) offset (?-1)*(select pagesize from config);

uses "constant scalar expressions" in the limit and offset clauses to allow one to dynamically select the "page" of results where the number of rows per page is stored in a configuration table, for naive application paging (which one should not ever do).

This, of course, leads to the question of the definition of the term "constant" in "constant scalar expression" which currently appears to mean "constant over the entire query including outer containing queries".

** Edited to include example for paging and definition of "constant"  
** Edited to correct also the referent o.x