English Français Deutsch Italiano Dansk Español

Query function

The syntax of the query function looks like the SQL syntax, but it works on a more low level

See also Sofawiki Database Primer and Differences between SQL and Sofawiki database

query = (selectstatement | importstatement | datastatement | wherestatement | groupstatement | orderstatement | limitstatement | UNION | exceptstatement | joinstatement | CROSS | COPY | POP | SWAP | projectstatement | ROTATE | renamestatement | formatstatement | numberformatstatement | calcstatement | templatestatement | outputstatement | stylestatement | # | FIELDS | VERBOSE)+

selectstatement = SELECT fieldlist (FROM (VIRTUAL)? name)? (wherestatement | IN valuelist)? (HINT string)?

fieldlist = field (, field)*

valuelist = string (:: string)*

optionlist = option (, value)*

option = parameter: value

name = string

wherestatement = WHERE field (operator string | dollaroperator expression)

operator = (!)? (numericoperator | stringoperator | relaxedstringoperator | otheroperator)

numericoperator = (= | < | > | <= | >=)

stringoperator = (== | =* | *= | *=* | << | >> | >=)

relaxedstringoperator = { ~~ | !~ | ~* | *~ | *~* )

otheroperator = (* | 0 | r= )

dollaroperator = $operator

expression = (field | $field | number | quotedstring | + | - | * | / | . | :: | ABS | SIGN | COPY | POP | SWAP | SUBSTR | REPLACE | TRIM | FUNCTION-function )*

quotedstring = "(.)+(""(.)*)*"

importstatement = IMPORT (TAB | FIELDS) name

datastatement = DATA wikifields

wikifields = ([[field::string]])*

groupstatement = GROUP (fieldaggregation) (, fieldaggregation)* BY fieldlist

fieldaggregation = field (COUNT | SUM | MIN | MAX | AVG | CONCAT)?

orderstatement = ORDER fieldorder (, fieldorder)*

fieldorder = field (NUMERIC)? (DESC)?

limistatement = LIMIT number number

orstatement = UNION

exceptstatement = EXCEPT field

joinstatement = (JOIN | LEFTJOIN | OUTERJOIN) field

projectstatement = PROJECT fieldlist

renamestatement = RENAME (field | * | # ) string (, field string)*

formatstatement = FORMAT field string

numberformatstatement = NUMERFORMAT field (number)? (, field (number)? )*

calcstatement = CALC field expression

templatestatement = TEMPLATE field templatename

outputstatement = OUTPUT (HTML | HTMLPAGED number | LIST | LISTPAGED number | FIXED (fieldlist)? | FIELDS | TAB | TABHEADER | TEXT | TEXTSPACE | ROWTEMPLATE string) | CHART (BAR|LINE|PIE) (optionlist)?

stylestatement = STYLE string

Note on quantificators on this formal definition:
* zero or more
? zero or one
+ one or more