fix predicate

This commit is contained in:
jackfoxy 2022-10-30 19:52:27 -07:00
parent e19c15667f
commit af65a41dab
6 changed files with 111 additions and 59 deletions

View File

@ -1,3 +1,5 @@
# ALTER INDEX
``` ```
ALTER INDEX [ <db-qualifer> ]{ <index-name> } ALTER INDEX [ <db-qualifer> ]{ <index-name> }
ON { <table-name> | <view-name> } ON { <table-name> | <view-name> }
@ -10,22 +12,25 @@ Discussion:
### _______________________________ ### _______________________________
# ALTER NAMESPACE
``` ```
ALTER NAMESPACE [ <database-name>. ]<namespace-name> ALTER NAMESPACE [ <database-name>. ]<namespace-name>
TRANSFER { TABLE | VIEW } [ <db-qualifer> ]{ <table-name> | <view-name> } TRANSFER { TABLE | VIEW } [ <db-qualifer> ]{ <table-name> | <view-name> }
``` ```
Discussion: Discussion:
The namespace *sys* cannot be altered, nor can objects be transferred out of it. The namespace *sys* cannot be altered, nor can objects be transferred in or out of it.
### _______________________________ ### _______________________________
# ALTER PROCEDURE
``` ```
ALTER { PROC | PROCEDURE } ALTER { PROC | PROCEDURE }
[<db-qualifer>]<procedure-name> [<db-qualifer>]<procedure-name>
[ { #<parameter-name> <data-type> } ] [ ,...n ] [ { #<parameter-name> <data-type> } ] [ ,...n ]
AS { sql_statement [ ;...n ] } AS { <urql command>; | *hoon } [ ;...n ]
``` ```
Discussion: Discussion:
@ -33,6 +38,7 @@ TBD
### _______________________________ ### _______________________________
# ALTER TABLE
``` ```
ALTER TABLE [ <db-qualifer> ]{ <table-name> } ALTER TABLE [ <db-qualifer> ]{ <table-name> }
@ -55,19 +61,20 @@ DROP FOREIGN KEY fk-1, fk-2
### _______________________________ ### _______________________________
# ALTER TRIGGER
``` ```
ALTER TRIGGER { [ <db-qualifer> ]{ <trigger-name> } | ALL ] ALTER TRIGGER { [ <db-qualifer> ]{ <trigger-name> } | ALL ]
ON { SERVER | <database.name> | <table-name> | <view-name> } ON { SERVER | <database.name> | <table-name> | <view-name> }
[ ENABLE | DISABLE ] [ ENABLE | DISABLE ]
``` ```
TBD
Discussion: Discussion:
Not for initial release. TBD
### _______________________________ ### _______________________________
# ALTER VIEW
``` ```
ALTER VIEW [ <db-qualifer> ]{ <view-name> } ALTER VIEW [ <db-qualifer> ]{ <view-name> }

View File

@ -1,4 +1,8 @@
`CREATE DATABASE <database-name>` # CREATE DATABASE
```
CREATE DATABASE <database-name>
```
Example: Example:
`CREATE DATABASE my-database` `CREATE DATABASE my-database`
@ -8,6 +12,7 @@ Discussion:
### _______________________________ ### _______________________________
# CREATE INDEX
``` ```
CREATE [ UNIQUE ] [ NONCLUSTERED | CLUSTERED ] INDEX <index-name> CREATE [ UNIQUE ] [ NONCLUSTERED | CLUSTERED ] INDEX <index-name>
@ -30,6 +35,7 @@ The `UNIQUE` option is not available for views.
### _______________________________ ### _______________________________
# CREATE NAMESPACE
`CREATE NAMESPACE [<database-name>.]<namespace-name>` `CREATE NAMESPACE [<database-name>.]<namespace-name>`
@ -38,12 +44,13 @@ Example:
### _______________________________ ### _______________________________
# CREATE PROCEDURE
``` ```
CREATE { PROC | PROCEDURE } CREATE { PROC | PROCEDURE }
[<db-qualifer>]<procedure-name> [<db-qualifer>]<procedure-name>
[ { #<parameter-name> <data-type> } ] [ ,...n ] [ { #<parameter-name> <data-type> } ] [ ,...n ]
AS { sql_statement [ ;...n ] } AS { <urql command>; | *hoon } [ ;...n ]
``` ```
Discussion: Discussion:
@ -52,6 +59,7 @@ Cannot be used to create database.
### _______________________________ ### _______________________________
# CREATE TABLE
``` ```
CREATE TABLE CREATE TABLE
@ -82,6 +90,7 @@ Discussion:
### _______________________________ ### _______________________________
# CREATE TRIGGER
``` ```
CREATE TRIGGER [ <db-qualifer> ]<trigger-name> CREATE TRIGGER [ <db-qualifer> ]<trigger-name>
@ -95,6 +104,7 @@ Not for initial release.
### _______________________________ ### _______________________________
# CREATE TYPE
`CREATE TYPE <type-name>` `CREATE TYPE <type-name>`
TBD TBD
@ -105,6 +115,7 @@ Possibly part of initial or early release.
### _______________________________ ### _______________________________
# CREATE VIEW
`CREATE VIEW [ <db-qualifer> ]<view-name> AS <query>` `CREATE VIEW [ <db-qualifer> ]<view-name> AS <query>`

View File

@ -1,5 +1,5 @@
``` ```
[ WITH <common-table-expression> ] [ WITH (<query>) AS <alias> [ ,...n ] ]
DELETE [ FROM ] [ <ship-qualifer> ]<table-name> DELETE [ FROM ] [ <ship-qualifer> ]<table-name>
[ WHERE <predicate> [ WHERE <predicate>
``` ```
@ -31,13 +31,13 @@ The `VALUES` or `<query>` must provide data for all columns in the expected orde
Tables in the namespace *sys* cannot be inserted into. Tables in the namespace *sys* cannot be inserted into.
`DEFAULT` is the bunt of the column type. `DEFAULT` is the bunt of the column type.
Cord values are represented in single quotes 'this is a cord'. Cord values are represented in single quotes 'this is a cord'.
Escape single quotes with double backslash thusly 'this is a cor\\'d'. Escape single quotes with double backslash thusly `'this is a cor\\'d'`.
### _______________________________ ### _______________________________
``` ```
[ WITH <common-table-expression> ] [ WITH (<query>) AS <alias> [ ,...n ] ]
MERGE [ INTO ] [ <ship-qualifer> ]<target-table-name> [ [ AS ] <alias> ] MERGE [ INTO ] [ <ship-qualifer> ]<target-table-name> [ [ AS ] <alias> ]
USING [ <ship-qualifer> ]<table-source-name> [ [ AS ] <alias> ] USING [ <ship-qualifer> ]<table-source-name> [ [ AS ] <alias> ]
ON <predicate> ON <predicate>
@ -77,7 +77,7 @@ Tables in the namespace *sys* cannot be truncated.
``` ```
[WITH <common-table-expression> ] [WITH (<query>) AS <alias> [ ,...n ] ]
UPDATE [ FROM ] [ <ship-qualifer> ]<table-name> UPDATE [ FROM ] [ <ship-qualifer> ]<table-name>
SET { <column-name> = { <scalar-expression> | DEFAULT | ~ } SET { <column-name> = { <scalar-expression> | DEFAULT | ~ }
[ WHERE <predicate> ] [ WHERE <predicate> ]

View File

@ -1,40 +1,54 @@
# Query
``` ```
<query> ::= <query> ::=
[WITH (<query>) AS <alias> [ ,...n ] ] [WITH (<query>) AS <alias> [ ,...n ] ]
[ { ]
FROM [ <ship-qualifer> ]<table-view> [ [AS] <alias> ] FROM [ <ship-qualifer> ]<table-view> [ [AS] <alias> ]
[ { { JOIN | LEFT JOIN | RIGHT JOIN | OUTER JOIN [ALL] } [ { { JOIN | LEFT JOIN | RIGHT JOIN | OUTER JOIN [ALL] }
[ <ship-qualifer> ]<table-view> [ [AS] <alias> ] [ <ship-qualifer> ]<table-view> [ [AS] <alias> ]
ON <predicate> ON <predicate>
} [ ...n ] } [ ...n ]
| CROSS JOIN | CROSS JOIN
[ <ship-qualifer> ]<table-view> [ [AS] <alias> ]
] ]
# Query
[ { SCALAR <scalar-name> [ AS ] <scalar-function> } [ ...n ] ] [ { SCALAR <scalar-name> [ AS ] <scalar-function> } [ ...n ] ]
[ WHERE <predicate> ] [ WHERE <predicate> ]
SELECT [ TOP <n> ] [ BOTTOM <n> ] [ DISTINCT ] SELECT [ TOP <n> ] [ BOTTOM <n> ] [ DISTINCT ]
{ * { * | { { [<ship-qualifer>]<table-view> | <alias> }.*
| {
{ [<ship-qualifer>]<table-view> | <alias> }.*
| { <qualified-column> | <constant> } [ [ AS ] <column-alias> ] | { <qualified-column> | <constant> } [ [ AS ] <column-alias> ]
| <scalar-name> | <scalar-name>
| <aggregate-name>( { <column> | <scalar-name> } ) | <aggregate-name>( { <column> | <scalar-name> } )
} [ ,...n ] } [ ,...n ]
} }
[ GROUP BY { <qualified-column> | <column-alias> | <column-ordinal> } [ ,...n ] [ GROUP BY { <qualified-column> | <column-alias> | <column-ordinal> } [ ,...n ]
[ HAVING <predicate> ] [ HAVING <predicate> ] ]
] [ ORDER BY { { <qualified-column> | <column-alias> | <column-ordinal> }
[ ORDER BY { { <qualified-column> | <column-alias> | <column-ordinal> } [ ASC | DESC ] } [ ,...n ] ] [ ASC | DESC ] } [ ,...n ] ]
[ INTO <table> ] [ INTO <table> ]
[ { UNION [ { UNION
| COMBINE | COMBINE
| EXCEPT | EXCEPT
| INTERSECT | INTERSECT
| DIVIDED BY [ WITH REMAINDER ] | DIVIDED BY [ WITH REMAINDER ]
}
<query> ] [ } ] [ ...n ]
``` ```
Cross database joins are allowed, but not cross ship joins.
`SELECT ... INTO` targets an existing table not otherwise in the query.
Do not use `ORDER BY` in Common Table Experessions (CTE, WITH clause) or in any query manipulated by set operators prior to the last of the queries, except when `TOP` or `BOTTOM` is specified.
Set operators apply the previous result set to the next query unless otherwise qualified by brackets `{ ... }`.
``` ```
<predicate> ::= <predicate> ::=
{ [ NOT ] <predicate> | ( <simple-predicate> ) } { [ NOT ] <predicate> | [ ( ] <simple-predicate> [ ) ] }
[ { { AND | OR } [ NOT ] { <predicate> | ( <simple-predicate> ) } [ { { AND | OR } [ NOT ] { <predicate> | [ ( ] <simple-predicate> [ ) ] }
[ ...n ] [ ...n ]
] ]
``` ```
@ -45,33 +59,46 @@ SELECT [ TOP <n> ] [ BOTTOM <n> ] [ DISTINCT ]
| expression [ NOT ] BETWEEN expression [ AND ] expression | expression [ NOT ] BETWEEN expression [ AND ] expression
| expression IS [ NOT ] DISTINCT FROM expression | expression IS [ NOT ] DISTINCT FROM expression
| expression [ NOT ] IN | expression [ NOT ] IN
{ <cte-one-column-query> | ( <value> ,...n ) } { <cte one column query> | ( <value> ,...n ) }
| expression <inequality-operator> { ALL | ANY} ( <cte-one-column-query> ) | expression <inequality operator> { ALL | ANY} ( <cte one column query> )
| [ NOT ] EXISTS { <column-value> | <cte-one-column-query> } } | [ NOT ] EXISTS { <column value> | <cte one column query> } }
``` ```
`DISTINCT FROM` is like equals `=` except comparing two `NOT EXISTS` yields false.
``` ```
<scalar-function> ::= <scalar-function> ::=
IF <predicate> THEN { <expression> | <scalar-function> } ELSE { <expression> | <scalar-function> } ENDIF IF <predicate> THEN { <expression> | <scalar-function> }
ELSE { <expression> | <scalar-function> } ENDIF
| CASE <expression> | CASE <expression>
WHEN { <expression> | <predicate> } THEN { <expression> | <scalar-function> } [ ...n ] WHEN { <expression> | <predicate> }
THEN { <expression> | <scalar-function> } [ ...n ]
[ ELSE { <expression> | <scalar-function> } ] [ ELSE { <expression> | <scalar-function> } ]
END END
| COALESCE ( <expression> [ ,...n ] ) | COALESCE ( <expression> [ ,...n ] )
| BEGIN <arithmetic on expressions and scalar functions> END | BEGIN <arithmetic on expressions and scalar functions> END
| *hoon (TBD) | *hoon (TBD)
``` ```
If a `CASE` expression uses `<predicate>`, the expected boolean (or loobean) logic applies.
If it uses `<expression>` `@`0 is treated as false and any other value as true (not loobean).
`COALESCE` returns the first `<expression>` in the list that exists where not existing occurs when selected `<expression>` value is not returned due to `LEFT` or `RIGHT JOIN` not matching.
``` ```
<expression> ::= <expression> ::=
{ { <column>
constant
| <column>
| <scalar-function> | <scalar-function>
| <scalar-query>
| <aggregate-name>( { <column> | <scalar-name> } ) | <aggregate-name>( { <column> | <scalar-name> } )
} }
``` ```
```
`<column> ::=
{ [ <qualified-column>
| <column-alias>
| <constant> }
```
``` ```
<binary-operator> ::= <binary-operator> ::=
{ = | <> | != | > | >= | !> | < | <= | !< } { = | <> | != | > | >= | !> | < | <= | !< }
@ -81,27 +108,3 @@ SELECT [ TOP <n> ] [ BOTTOM <n> ] [ DISTINCT ]
<qualified-column> ::= <qualified-column> ::=
[ [ <ship-qualifer> ]<table-view> | <alias> } ].<column-name> [ [ <ship-qualifer> ]<table-view> | <alias> } ].<column-name>
``` ```
```
`<column> ::=
{ [ <qualified-column>
| <column-alias>
| <constant> }
```
Discussion:
Not shown in diagrams, parentheses distinguish order of operations for binary conjunctions `AND` and `OR`.
Set operators apply the previous result set to the next query unless otherwise qualified by parentheses.
`ORDER BY` is not recommended in Common Table Experessions (CTE, WITH clause) or in any query joined by set operators prior to the last of the queries, except when `TOP` or `BOTTOM` is specified.
`SELECT INTO` targets an existing table not otherwise in the query.
`COALESCE` returns the first `<expression>` in the list that does not evaluate to `~` (in the case of unit) or not in the selected `<expression>` due to `LEFT` or `RIGHT JOIN`.
If a `CASE WHEN` expression is a `<predicate>`, the expected boolean (or loobean) logic applies. If it is a <expression> atom value 0 is treated as false and any other value as true (not loobean).
Cross database joins are allowed, but not cross ship joins.
`DISTINCT FROM` is like equals, `=`, except comparing two nulls will yield false.

View File

@ -327,7 +327,10 @@
?: ?=([[@ @ [@ %~] @] @ @ [@ %~] @] a) :: <type> no action, <type> no action ?: ?=([[@ @ [@ %~] @] @ @ [@ %~] @] a) :: <type> no action, <type> no action
~ ~
!! !!
++ end-or-next-command ~+ (cold %end-command ;~(pose ;~(plug whitespace mic) whitespace mic)) ++ end-or-next-command ;~ plug
(cold %end-command ;~(pose ;~(plug whitespace mic) whitespace mic))
(easy ~)
==
++ alias ++ alias
%+ cook %+ cook
|=(a=tape (rap 3 ^-((list ,@) a))) |=(a=tape (rap 3 ^-((list ,@) a)))
@ -788,6 +791,8 @@
?: =(+>-.b.a %par) ?: =(+>-.b.a %par)
:: stand-alone tree :: stand-alone tree
?: =((lent b.a) 3) ^$(b.a +>+.b.a, resolved [+<.b.a resolved]) ?: =((lent b.a) 3) ^$(b.a +>+.b.a, resolved [+<.b.a resolved])
?: ?&((gth (lent resolved) 1) =(-.resolved %pal)) $(b.a +>+.b.a, working-tree +<.b.a)
?: =((lent b.a) 4) $(b.a ~, working-tree +<.b.a)
$(b.a +>+>+.b.a, working-tree [+>+<.b.a +<.b.a +>+>-.b.a]) $(b.a +>+>+.b.a, working-tree [+>+<.b.a +<.b.a +>+>-.b.a])
$(b.a +>.b.a, working-tree [+>-.b.a +<.b.a +>+<.b.a]) $(b.a +>.b.a, working-tree [+>-.b.a +<.b.a +>+<.b.a])
?: =(-.b.a %par) ?: =(-.b.a %par)
@ -1146,13 +1151,38 @@
== ==
++ parse-query ;~ plug ++ parse-query ;~ plug
parse-object-and-joins parse-object-and-joins
(star parse-scalar) (stag %scalars (star parse-scalar))
;~(pfix whitespace ;~(plug (cold %where (jester 'where')) parse-predicate)) ;~(pfix whitespace ;~(plug (cold %where (jester 'where')) parse-predicate))
parse-select parse-select
parse-group-by parse-group-by
parse-order-by parse-order-by
end-or-next-command end-or-next-command
== ==
++ produce-joins
|= a=* ::(list *)
=/ joins=(list joined-object:ast) ~
^- (list joined-object:ast)
|-
?: =(a ~) (flop joins)
?: ?=(joined-object:ast -.a) $(joins [-.a joins], a +.a)
::(crash "cannot produce join from {<-.a>}")
!!
++ produce-from
|= a=* ::(list *)
^- from:ast
?: =(%query-object -<.a) ::?&(=(%query-object -<.a) (gth (lent a) 0))
?: =(+.a ~) (from:ast %from -.a ~)
(from:ast -.a (produce-joins +.a))
::(crash "cannot produce query-object from {<-.a>}")
!!
++ cook-query
|= parsed=(list *)
=| from=from:ast
|-
?: =(-.parsed %query) $(from (produce-from +<.parsed), parsed +>.parsed)
!!
++ parse-revoke ;~ plug ++ parse-revoke ;~ plug
:: permission :: permission
;~(pfix whitespace ;~(pose (jester 'adminread') (jester 'readonly') (jester 'readwrite') (jester 'all'))) ;~(pfix whitespace ;~(pose (jester 'adminread') (jester 'readonly') (jester 'readwrite') (jester 'all')))

View File

@ -140,6 +140,7 @@
== ==
+$ from +$ from
$: $:
%from
object=query-object object=query-object
joins=(list joined-object) joins=(list joined-object)
== ==