/ Check-in [a6dffecc]
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 | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a6dffecc6b35c618cc5e5a06892765bdbec587dcd0ae8686c231a21516e38eab
User & Date: dan 2018-07-06 14:31:26
Context
2018-07-06
17:19
Try to improve the error messages for misformed frame specifications in window definitions. check-in: 927b95a0 user: drh tags: trunk
14:31
Also disallow non-constant expressions in "<expr> PRECEDING" or "<expr> FOLLOWING" clauses. check-in: a6dffecc user: dan tags: trunk
14:15
Ensure an error is returned if the user specifies an unsupported frame type. check-in: 0f3f8fcd user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/window.c.

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

Changes to test/window6.test.

   250    250   } {1 {near "PRECEDING": syntax error}}
   251    251   
   252    252   foreach {tn frame} {
   253    253     1 "BETWEEN CURRENT ROW AND 4 PRECEDING"
   254    254     2 "4 FOLLOWING"
   255    255     3 "BETWEEN 4 FOLLOWING AND CURRENT ROW"
   256    256     4 "BETWEEN 4 FOLLOWING AND 2 PRECEDING"
          257  +  5 "BETWEEN a PRECEDING AND 2 FOLLOWING"
          258  +  6 "BETWEEN 4 PRECEDING AND a FOLLOWING"
   257    259   } {
   258    260     do_catchsql_test 9.7.$tn "
   259    261       WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<5)
   260    262       SELECT count() OVER (
   261    263           ORDER BY x ROWS $frame 
   262    264       ) FROM c;
   263    265     " {1 {unsupported window-frame type}}
   264    266   }
   265    267   
   266    268   finish_test
   267    269