SQLite

Check-in [a6dffecc6b]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Also disallow non-constant expressions in "<expr> PRECEDING" or "<expr> FOLLOWING" clauses.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a6dffecc6b35c618cc5e5a06892765bdbec587dcd0ae8686c231a21516e38eab
User & Date: dan 2018-07-06 14:31:26.509
Context
2018-07-06
17:19
Try to improve the error messages for misformed frame specifications in window definitions. (check-in: 927b95a081 user: drh tags: trunk)
14:31
Also disallow non-constant expressions in "<expr> PRECEDING" or "<expr> FOLLOWING" clauses. (check-in: a6dffecc6b user: dan tags: trunk)
14:15
Ensure an error is returned if the user specifies an unsupported frame type. (check-in: 0f3f8fcde1 user: dan tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/window.c.
851
852
853
854
855
856
857


858
859
860
861
862
863
864
  ** The parser ensures that "UNBOUNDED PRECEDING" cannot be used as an ending
  ** boundary, and than "UNBOUNDED FOLLOWING" cannot be used as a starting
  ** frame boundary.
  */
  if( eType==TK_RANGE && (pStart || pEnd) 
   || (eStart==TK_CURRENT && eEnd==TK_PRECEDING)
   || (eStart==TK_FOLLOWING && (eEnd==TK_PRECEDING || eEnd==TK_CURRENT))


  ){
    sqlite3ErrorMsg(pParse, "unsupported window-frame type");
  }else{
    pWin = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
  }

  if( pWin ){







>
>







851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
  ** The parser ensures that "UNBOUNDED PRECEDING" cannot be used as an ending
  ** boundary, and than "UNBOUNDED FOLLOWING" cannot be used as a starting
  ** frame boundary.
  */
  if( eType==TK_RANGE && (pStart || pEnd) 
   || (eStart==TK_CURRENT && eEnd==TK_PRECEDING)
   || (eStart==TK_FOLLOWING && (eEnd==TK_PRECEDING || eEnd==TK_CURRENT))
   || (0==sqlite3ExprIsConstantOrFunction(pStart, 0))
   || (0==sqlite3ExprIsConstantOrFunction(pEnd, 0))
  ){
    sqlite3ErrorMsg(pParse, "unsupported window-frame type");
  }else{
    pWin = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
  }

  if( pWin ){
Changes to test/window6.test.
250
251
252
253
254
255
256


257
258
259
260
261
262
263
} {1 {near "PRECEDING": syntax error}}

foreach {tn frame} {
  1 "BETWEEN CURRENT ROW AND 4 PRECEDING"
  2 "4 FOLLOWING"
  3 "BETWEEN 4 FOLLOWING AND CURRENT ROW"
  4 "BETWEEN 4 FOLLOWING AND 2 PRECEDING"


} {
  do_catchsql_test 9.7.$tn "
    WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<5)
    SELECT count() OVER (
        ORDER BY x ROWS $frame 
    ) FROM c;
  " {1 {unsupported window-frame type}}







>
>







250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
} {1 {near "PRECEDING": syntax error}}

foreach {tn frame} {
  1 "BETWEEN CURRENT ROW AND 4 PRECEDING"
  2 "4 FOLLOWING"
  3 "BETWEEN 4 FOLLOWING AND CURRENT ROW"
  4 "BETWEEN 4 FOLLOWING AND 2 PRECEDING"
  5 "BETWEEN a PRECEDING AND 2 FOLLOWING"
  6 "BETWEEN 4 PRECEDING AND a FOLLOWING"
} {
  do_catchsql_test 9.7.$tn "
    WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<5)
    SELECT count() OVER (
        ORDER BY x ROWS $frame 
    ) FROM c;
  " {1 {unsupported window-frame type}}