/ Check-in [28ce42f7]
Login

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

Overview
Comment:Make the FROM clause on a SELECT optional. If omitted, the result of the SELECT is a single row consisting of the values in the expression list. (CVS 520)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 28ce42f7872e2660faa22e66b508db9b1f046af0
User & Date: drh 2002-04-06 13:57:43
Context
2002-04-06
14:10
Added the last_insert_rowid() SQL function. (CVS 521) check-in: 6aca3f86 user: drh tags: trunk
13:57
Make the FROM clause on a SELECT optional. If omitted, the result of the SELECT is a single row consisting of the values in the expression list. (CVS 520) check-in: 28ce42f7 user: drh tags: trunk
2002-04-04
15:10
Add an fflush() call to shell.c to insure that all output has been written before we prompt for a new line of input. (CVS 519) check-in: 93227418 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/parse.y.

    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains SQLite's grammar for SQL.  Process this file
    13     13   ** using the lemon parser generator to generate C code that runs
    14     14   ** the parser.  Lemon will also generate a header file containing
    15     15   ** numeric codes for all of the tokens.
    16     16   **
    17         -** @(#) $Id: parse.y,v 1.60 2002/04/04 02:10:57 drh Exp $
           17  +** @(#) $Id: parse.y,v 1.61 2002/04/06 13:57:43 drh Exp $
    18     18   */
    19     19   %token_prefix TK_
    20     20   %token_type {Token}
    21     21   %default_type {Token}
    22     22   %extra_argument {Parse *pParse}
    23     23   %syntax_error {
    24     24     sqliteSetString(&pParse->zErrMsg,"syntax error",0);
................................................................................
   267    267   %type seltablist {IdList*}
   268    268   %destructor seltablist {sqliteIdListDelete($$);}
   269    269   %type stl_prefix {IdList*}
   270    270   %destructor stl_prefix {sqliteIdListDelete($$);}
   271    271   %type from {IdList*}
   272    272   %destructor from {sqliteIdListDelete($$);}
   273    273   
          274  +from(A) ::= .                                 {A = sqliteMalloc(sizeof(*A));}
   274    275   from(A) ::= FROM seltablist(X).               {A = X;}
   275    276   stl_prefix(A) ::= seltablist(X) COMMA.        {A = X;}
   276    277   stl_prefix(A) ::= .                           {A = 0;}
   277    278   seltablist(A) ::= stl_prefix(X) ids(Y).       {A = sqliteIdListAppend(X,&Y);}
   278    279   seltablist(A) ::= stl_prefix(X) ids(Y) as ids(Z). {
   279    280     A = sqliteIdListAppend(X,&Y);
   280    281     sqliteIdListAddAlias(A,&Z);

Changes to test/select1.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is testing the SELECT statement.
    13     13   #
    14         -# $Id: select1.test,v 1.23 2002/04/04 02:10:57 drh Exp $
           14  +# $Id: select1.test,v 1.24 2002/04/06 13:57:43 drh Exp $
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   
    19     19   # Try to select on a non-existant table.
    20     20   #
    21     21   do_test select1-1.1 {
................................................................................
   621    621     }
   622    622   } {t3.a 1 t3.b 2 max(a) 3 max(b) 4}
   623    623   do_test select1-11.15 {
   624    624     execsql2 {
   625    625       SELECT y.*, t3.* FROM t3, (SELECT max(a), max(b) FROM t4) AS y
   626    626     }
   627    627   } {y.max(a) 3 y.max(b) 4 t3.a 1 t3.b 2}
          628  +
          629  +# Tests of SELECT statements without a FROM clause.
          630  +#
          631  +do_test select1-12.1 {
          632  +  execsql2 {
          633  +    SELECT 1+2+3
          634  +  }
          635  +} {1+2+3 6}
          636  +do_test select1-12.2 {
          637  +  execsql2 {
          638  +    SELECT 1,'hello',2
          639  +  }
          640  +} {1 1 'hello' hello 2 2}
          641  +do_test select1-12.3 {
          642  +  execsql2 {
          643  +    SELECT 1 AS 'a','hello' AS 'b',2 AS 'c'
          644  +  }
          645  +} {a 1 b hello c 2}
          646  +do_test select1-12.4 {
          647  +  execsql {
          648  +    DELETE FROM t3;
          649  +    INSERT INTO t3 VALUES(1,2);
          650  +    SELECT * FROM t3 UNION SELECT 3 AS 'a', 4 ORDER BY a;
          651  +  }
          652  +} {1 2 3 4}
          653  +do_test select1-12.5 {
          654  +  execsql {
          655  +    SELECT 3, 4 UNION SELECT * FROM t3;
          656  +  }
          657  +} {1 2 3 4}
          658  +do_test select1-12.6 {
          659  +  execsql {
          660  +    SELECT * FROM t3 WHERE a=(SELECT 1);
          661  +  }
          662  +} {1 2}
          663  +do_test select1-12.7 {
          664  +  execsql {
          665  +    SELECT * FROM t3 WHERE a=(SELECT 2);
          666  +  }
          667  +} {}
   628    668   
   629    669   finish_test

Changes to www/changes.tcl.

    24     24     puts "<DT><B>$date</B></DT>"
    25     25     puts "<DD><P><UL>$desc</UL></P></DD>"
    26     26   }
    27     27   
    28     28   chng {2002 Apr 03 (2.4.7)} {
    29     29   <li>Add the ability to put TABLE.* in the column list of a
    30     30       SELECT statement.</li>
           31  +<li>Permit SELECT statements without a FROM clause.</li>
    31     32   }
    32     33   
    33     34   chng {2002 Apr 02 (2.4.6)} {
    34     35   <li>Bug fix: Correctly handle terms in the WHERE clause of a join that
    35     36       do not contain a comparison operator.</li>
    36     37   }
    37     38   

Changes to www/lang.tcl.

     1      1   #
     2      2   # Run this Tcl script to generate the sqlite.html file.
     3      3   #
     4         -set rcsid {$Id: lang.tcl,v 1.29 2002/03/28 14:20:08 drh Exp $}
            4  +set rcsid {$Id: lang.tcl,v 1.30 2002/04/06 13:57:44 drh Exp $}
     5      5   
     6      6   puts {<html>
     7      7   <head>
     8      8     <title>Query Language Understood By SQLite</title>
     9      9   </head>
    10     10   <body bgcolor=white>
    11     11   <h1 align=center>
................................................................................
   951    951   <a href="#insert">INSERT command</a> documentation for additional
   952    952   information.</p>  
   953    953   }
   954    954   
   955    955   Section SELECT select
   956    956   
   957    957   Syntax {sql-statement} {
   958         -SELECT <result> FROM <table-list>
          958  +SELECT <result> [FROM <table-list>]
   959    959   [WHERE <expression>]
   960    960   [GROUP BY <expr-list>]
   961    961   [HAVING <expression>]
   962    962   [<compound-op> <select>]*
   963    963   [ORDER BY <sort-expr-list>]
   964    964   [LIMIT <integer> [OFFSET <integer>]]
   965    965   } {result} {
................................................................................
   989    989   puts "[Operator *] then all columns of all tables are substituted"
   990    990   puts {for that one expression.</p>
   991    991   
   992    992   <p>The query is executed again one or more tables specified after
   993    993   the FROM keyword.  If more than one table is specified, then the
   994    994   query is against the (inner) join of the various tables.  A sub-query
   995    995   in parentheses may be substituted for any table name in the FROM clause.
          996  +The entire FROM clause may be omitted, in which case the result is a
          997  +single row consisting of the values of the expression list.
   996    998   </p>
   997    999   
   998   1000   <p>The WHERE clause can be used to limit the number of rows over
   999   1001   which the query operates.  In the current implementation,
  1000   1002   indices will only be used to
  1001   1003   optimize the query if WHERE expression contains equality comparisons
  1002   1004   connected by the AND operator.</p>