SitemapMcMillan Enterprises, Inc.Python Pages Sockets HOWTO Distributing Python Programs A Python C++ API Embedding Python Stackless Python MkSQL MkSQL Users Guide MkSQL Grammar Import Hooks Java Samples Sponsoring ME Inc. About ME Inc. |
MkSQL's Dialect of SQLContents: MkSQL implements a fairly full subset of SQL 92 grammar. It does have it's peculiarities.
subquery ::= selectstmt [ ORDER BY orderbylist ] Note that you can't use an ORDER BY clause on a UNION, INTERSECT or EXCEPT statement. Note that you can construct statements like "select ... INTERSECT ( select ... UNION select ... )". selectstmt ::= SELECT selectlist FROM tablelist [ WHERE condition ] [ GROUP BY columnlist [ HAVING condition ] ] A few things worth noting about columns:
The last two restrictions are because if a result set column has no alias (and is more than a simple column reference), the text used to define the expression becomes the alias. MkSQL implements all the conditions you would expect, and a few you may not. The IN clause is fairly advanced:
More generally, we have: MkSQL implements the most important of the JOIN types: the CROSS JOIN, the NATURAL JOIN, LEFT and RIGHT OUTER JOINs, JOIN ON and JOIN USING. (This list lacks the FULL OUTER JOIN and the UNION JOIN - both of which are very strange beasts indeed!). The CROSS JOIN is the product of two tables. The following statements are equivalent: The NATURAL JOIN is the INNER JOIN of two tables on common column names. So if frequents and serves have bar as the only common column name, these two statements are equivalent (and the first will be faster):
Further, these are equivalent to the following JOIN ON (where the columns to use in the join can be specified):
JOIN ON is just a way of moving a condition out of the WHERE clause. These are equivalent:
NATURAL JOINs and JOIN ONs may also specify LEFT or RIGHT. All rows from the appropriate table will be included, whether or not they have a match with the other table. Where normal SQL would fill the unavailable columns with NULLs, MkSQL fills them with default values.
These features can be very valuable. For example, the following query:
The second query will be much faster, since the subquery is not correlated. The subquery will only be executed once (while in the "classic" spelling, it will be executed for every row in the outer query). The UPDATE statement allows (per the SQL standard) SET col=subquery. I have never tested this, and wouldn't be surprised if it didn't work properly. I would never use this in SQL, because it's too fragile (the subquery must return exactly one row; any other result is, in effect, a runtime syntax error - yech). The INSERT statement allows subqueries:
The DELETE statement should hold no surprises. Of the DDL statements, only CREATE TABLE is recognized. createstmt ::= CREATE TABLE tablenm ( defitem, ... ) The optional size parameter on a column definition (which uses literal [...]) is ignored - MetaKit doesn't care. colconstraint ::= { UNIQUE | PRIMARY KEY | FOREIGN KEY REFERENCES table (column) | CHECK "code" } A CHECK constraint is specified as source (a lambda, taking one arg - the value being checked). The double quote was chosen as delimiter because there should be no need to use double quotes within the Python code. If you try (even escaping the double quote), it won't work. tblconstaint ::= { UNIQUE (column, ...) | PRIMARY KEY (column, ...) | FOREIGN KEY (column, ...) REFERENCES table (column, ...) } In both column and table constraints, PRIMARY KEY is treated exactly like UNIQUE. This may change in a future version and be used to give the underlying view a native order, but not yet.
[0b1] If you are querying an existing Metakit database, MkSQL can now access subviews. Note that you cannot create or update them in any way (only SELECT statements understand anything about subviews). SELECT .... FROM FLATTEN(view.subview) will do a Metakit In addition, a subquery's FROM may reference a subview attribute (either as subviewname or view.subview) of a view referenced by the outer query. |
| copyright 1999-2002 McMillan Enterprises, Inc. |
|