This repository was archived by the owner on Nov 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathdoc.go
2672 lines (2669 loc) · 92.8 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2014 The ql Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//MAYBE set operations
//MAYBE +=, -=, ...
//TODO verify there's a graceful failure for a 2G+ blob on a 32 bit machine.
// Package ql implements a pure Go embedded SQL database engine.
//
// QL is a member of the SQL family of languages. It is less complex and less
// powerful than SQL (whichever specification SQL is considered to be).
//
// Change list
//
// 2018-11-04: Back end file format V2 is now released. To use the new format
// for newly created databases set the FileFormat field in *Options passed to
// OpenFile to value 2 or use the driver named "ql2" instead of "ql".
//
// - Both the old and new driver will properly open and use, read and write the
// old (V1) or new file (V2) format of an existing database.
//
// - V1 format has a record size limit of ~64 kB. V2 format record size limit
// is math.MaxInt32.
//
// - V1 format uncommitted transaction size is limited by memory resources. V2
// format uncommitted transaction is limited by free disk space.
//
// - A direct consequence of the previous is that small transactions perform
// better using V1 format and big transactions perform better using V2 format.
//
// - V2 format uses substantially less memory.
//
// 2018-08-02: Release v1.2.0 adds initial support for Go modules.
//
// 2017-01-10: Release v1.1.0 fixes some bugs and adds a configurable WAL
// headroom.
//
// https://github.com/cznic/ql/issues/140
//
// 2016-07-29: Release v1.0.6 enables alternatively using = instead of == for
// equality operation.
//
// https://github.com/cznic/ql/issues/131
//
// 2016-07-11: Release v1.0.5 undoes vendoring of lldb. QL now uses stable lldb
// (github.com/cznic/lldb).
//
// https://github.com/cznic/ql/issues/128
//
// 2016-07-06: Release v1.0.4 fixes a panic when closing the WAL file.
//
// https://github.com/cznic/ql/pull/127
//
// 2016-04-03: Release v1.0.3 fixes a data race.
//
// https://github.com/cznic/ql/issues/126
//
// 2016-03-23: Release v1.0.2 vendors github.com/cznic/exp/lldb and
// github.com/camlistore/go4/lock.
//
// 2016-03-17: Release v1.0.1 adjusts for latest goyacc. Parser error messages
// are improved and changed, but their exact form is not considered a API
// change.
//
// 2016-03-05: The current version has been tagged v1.0.0.
//
// 2015-06-15: To improve compatibility with other SQL implementations, the
// count built-in aggregate function now accepts * as its argument.
//
// 2015-05-29: The execution planner was rewritten from scratch. It should use
// indices in all places where they were used before plus in some additional
// situations. It is possible to investigate the plan using the newly added
// EXPLAIN statement. The QL tool is handy for such analysis. If the planner
// would have used an index, but no such exists, the plan includes hints in
// form of copy/paste ready CREATE INDEX statements.
//
// The planner is still quite simple and a lot of work on it is yet ahead. You
// can help this process by filling an issue with a schema and query which
// fails to use an index or indices when it should, in your opinion. Bonus
// points for including output of `ql 'explain <query>'`.
//
// 2015-05-09: The grammar of the CREATE INDEX statement now accepts an
// expression list instead of a single expression, which was further limited to
// just a column name or the built-in id(). As a side effect, composite
// indices are now functional. However, the values in the expression-list style
// index are not yet used by other statements or the statement/query planner.
// The composite index is useful while having UNIQUE clause to check for
// semantically duplicate rows before they get added to the table or when such
// a row is mutated using the UPDATE statement and the expression-list style
// index tuple of the row is thus recomputed.
//
// 2015-05-02: The Schema field of table __Table now correctly reflects any
// column constraints and/or defaults. Also, the (*DB).Info method now has that
// information provided in new ColumInfo fields NotNull, Constraint and
// Default.
//
// 2015-04-20: Added support for {LEFT,RIGHT,FULL} [OUTER] JOIN.
//
// 2015-04-18: Column definitions can now have constraints and defaults.
// Details are discussed in the "Constraints and defaults" chapter below the
// CREATE TABLE statement documentation.
//
// 2015-03-06: New built-in functions formatFloat and formatInt. Thanks
// urandom! (https://github.com/urandom)
//
// 2015-02-16: IN predicate now accepts a SELECT statement. See the updated
// "Predicates" section.
//
// 2015-01-17: Logical operators || and && have now alternative spellings: OR
// and AND (case insensitive). AND was a keyword before, but OR is a new one.
// This can possibly break existing queries. For the record, it's a good idea
// to not use any name appearing in, for example, [7] in your queries as the
// list of QL's keywords may expand for gaining better compatibility with
// existing SQL "standards".
//
// 2015-01-12: ACID guarantees were tightened at the cost of performance in
// some cases. The write collecting window mechanism, a formerly used
// implementation detail, was removed. Inserting rows one by one in a
// transaction is now slow. I mean very slow. Try to avoid inserting single
// rows in a transaction. Instead, whenever possible, perform batch updates of
// tens to, say thousands of rows in a single transaction. See also:
// http://www.sqlite.org/faq.html#q19, the discussed synchronization principles
// involved are the same as for QL, modulo minor details.
//
// Note: A side effect is that closing a DB before exiting an application, both
// for the Go API and through database/sql driver, is no more required,
// strictly speaking. Beware that exiting an application while there is an open
// (uncommitted) transaction in progress means losing the transaction data.
// However, the DB will not become corrupted because of not closing it. Nor
// that was the case before, but formerly failing to close a DB could have
// resulted in losing the data of the last transaction.
//
// 2014-09-21: id() now optionally accepts a single argument - a table name.
//
// 2014-09-01: Added the DB.Flush() method and the LIKE pattern matching
// predicate.
//
// 2014-08-08: The built in functions max and min now accept also time values.
// Thanks opennota! (https://github.com/opennota)
//
// 2014-06-05: RecordSet interface extended by new methods FirstRow and Rows.
//
// 2014-06-02: Indices on id() are now used by SELECT statements.
//
// 2014-05-07: Introduction of Marshal, Schema, Unmarshal.
//
// 2014-04-15:
//
// Added optional IF NOT EXISTS clause to CREATE INDEX and optional IF EXISTS
// clause to DROP INDEX.
//
// 2014-04-12:
//
// The column Unique in the virtual table __Index was renamed to IsUnique
// because the old name is a keyword. Unfortunately, this is a breaking change,
// sorry.
//
// 2014-04-11: Introduction of LIMIT, OFFSET.
//
// 2014-04-10: Introduction of query rewriting.
//
// 2014-04-07: Introduction of indices.
//
// Building non CGO QL
//
// QL imports zappy[8], a block-based compressor, which speeds up its
// performance by using a C version of the compression/decompression
// algorithms. If a CGO-free (pure Go) version of QL, or an app using QL, is
// required, please include 'purego' in the -tags option of go
// {build,get,install}. For example:
//
// $ go get -tags purego github.com/cznic/ql
//
// If zappy was installed before installing QL, it might be necessary to
// rebuild zappy first (or rebuild QL with all its dependencies using the -a
// option):
//
// $ touch "$GOPATH"/src/github.com/cznic/zappy/*.go
// $ go install -tags purego github.com/cznic/zappy
// $ go install github.com/cznic/ql
//
// Notation
//
// The syntax is specified using Extended Backus-Naur Form (EBNF)
//
// Production = production_name "=" [ Expression ] "." .
// Expression = Alternative { "|" Alternative } .
// Alternative = Term { Term } .
// Term = production_name | token [ "…" token ] | Group | Option | Repetition .
// Group = "(" Expression ")" .
// Option = "[" Expression "]" .
// Repetition = "{" Expression "}" .
// Productions are expressions constructed from terms and the following operators, in increasing precedence
//
// | alternation
// () grouping
// [] option (0 or 1 times)
// {} repetition (0 to n times)
//
// Lower-case production names are used to identify lexical tokens.
// Non-terminals are in CamelCase. Lexical tokens are enclosed in double quotes
// "" or back quotes ``.
//
// The form a … b represents the set of characters from a through b as
// alternatives. The horizontal ellipsis … is also used elsewhere in the spec
// to informally denote various enumerations or code snippets that are not
// further specified.
//
// QL source code representation
//
// QL source code is Unicode text encoded in UTF-8. The text is not
// canonicalized, so a single accented code point is distinct from the same
// character constructed from combining an accent and a letter; those are
// treated as two code points. For simplicity, this document will use the
// unqualified term character to refer to a Unicode code point in the source
// text.
//
// Each code point is distinct; for instance, upper and lower case letters are
// different characters.
//
// Implementation restriction: For compatibility with other tools, the parser
// may disallow the NUL character (U+0000) in the statement.
//
// Implementation restriction: A byte order mark is disallowed anywhere in QL
// statements.
//
// Characters
//
// The following terms are used to denote specific character classes
//
// newline = . // the Unicode code point U+000A
// unicode_char = . // an arbitrary Unicode code point except newline
// ascii_letter = "a" … "z" | "A" … "Z" .
// unicode_letter = . // Unicode category L.
// unicode_digit = . // Unocode category D.
//
// Letters and digits
//
// The underscore character _ (U+005F) is considered a letter.
//
// letter = ascii_letter | unicode_letter | "_" .
// decimal_digit = "0" … "9" .
// octal_digit = "0" … "7" .
// hex_digit = "0" … "9" | "A" … "F" | "a" … "f" .
//
// Lexical elements
//
// Lexical elements are comments, tokens, identifiers, keywords, operators and
// delimiters, integer, floating-point, imaginary, rune and string literals and
// QL parameters.
//
// Comments
//
// There are three forms of comments
//
// Line comments start with the character sequence // or -- and stop at the end
// of the line. A line comment acts like a space.
//
// General comments start with the character sequence /* and continue through
// the character sequence */. A general comment acts like a space.
//
// Comments do not nest.
//
// Tokens
//
// Tokens form the vocabulary of QL. There are four classes: identifiers,
// keywords, operators and delimiters, and literals. White space, formed from
// spaces (U+0020), horizontal tabs (U+0009), carriage returns (U+000D), and
// newlines (U+000A), is ignored except as it separates tokens that would
// otherwise combine into a single token.
//
// Semicolons
//
// The formal grammar uses semicolons ";" as separators of QL statements. A
// single QL statement or the last QL statement in a list of statements can
// have an optional semicolon terminator. (Actually a separator from the
// following empty statement.)
//
// Identifiers
//
// Identifiers name entities such as tables or record set columns. An
// identifier is a sequence of one or more letters and digits. The first
// character in an identifier must be a letter.
//
// identifier = letter { letter | decimal_digit | unicode_digit } .
//
// For example
//
// price
// _tmp42
// Sales
//
// No identifiers are predeclared, however note that no keyword can be used as
// an identifier. Identifiers starting with two underscores are used for meta
// data virtual tables names. For forward compatibility, users should generally
// avoid using any identifiers starting with two underscores. For example
//
// __Column
// __Column2
// __Index
// __Table
//
// Keywords
//
// The following keywords are reserved and may not be used as identifiers.
//
// ADD complex128 FROM LEFT string
// ALTER complex64 FULL LIKE TABLE
// AND CREATE GROUP LIMIT time
// AS DEFAULT IF NOT TRANSACTION
// ASC DELETE IN NULL true
// BEGIN DESC INDEX OFFSET TRUNCATE
// BETWEEN DISTINCT INSERT ON uint
// bigint DROP int OR uint16
// bigrat duration int16 ORDER uint32
// blob EXISTS int32 OUTER uint64
// bool EXPLAIN int64 RIGHT uint8
// BY false int8 ROLLBACK UNIQUE
// byte float INTO rune UPDATE
// COLUMN float32 IS SELECT VALUES
// COMMIT float64 JOIN SET WHERE
//
// Keywords are not case sensitive.
//
// Operators and Delimiters
//
// The following character sequences represent operators, delimiters, and other
// special tokens
//
// + & && == != ( )
// - | || < <= [ ]
// * ^ > >= , ;
// / << = .
// % >> !
// &^
//
// Operators consisting of more than one character are referred to by names in
// the rest of the documentation
//
// andand = "&&" .
// andnot = "&^" .
// lsh = "<<" .
// le = "<=" .
// eq = "==" | "=" .
// ge = ">=" .
// neq = "!=" .
// oror = "||" .
// rsh = ">>" .
//
// Integer literals
//
// An integer literal is a sequence of digits representing an integer constant.
// An optional prefix sets a non-decimal base: 0 for octal, 0x or 0X for
// hexadecimal. In hexadecimal literals, letters a-f and A-F represent values
// 10 through 15.
//
// int_lit = decimal_lit | octal_lit | hex_lit .
// decimal_lit = ( "1" … "9" ) { decimal_digit } .
// octal_lit = "0" { octal_digit } .
// hex_lit = "0" ( "x" | "X" ) hex_digit { hex_digit } .
//
// For example
//
// 42
// 0600
// 0xBadFace
// 1701411834604692
//
// Floating-point literals
//
// A floating-point literal is a decimal representation of a floating-point
// constant. It has an integer part, a decimal point, a fractional part, and an
// exponent part. The integer and fractional part comprise decimal digits; the
// exponent part is an e or E followed by an optionally signed decimal
// exponent. One of the integer part or the fractional part may be elided; one
// of the decimal point or the exponent may be elided.
//
// float_lit = decimals "." [ decimals ] [ exponent ] |
// decimals exponent |
// "." decimals [ exponent ] .
// decimals = decimal_digit { decimal_digit } .
// exponent = ( "e" | "E" ) [ "+" | "-" ] decimals .
//
// For example
//
// 0.
// 72.40
// 072.40 // == 72.40
// 2.71828
// 1.e+0
// 6.67428e-11
// 1E6
// .25
// .12345E+5
//
// Imaginary literals
//
// An imaginary literal is a decimal representation of the imaginary part of a
// complex constant. It consists of a floating-point literal or decimal integer
// followed by the lower-case letter i.
//
// imaginary_lit = (decimals | float_lit) "i" .
//
// For example
//
// 0i
// 011i // == 11i
// 0.i
// 2.71828i
// 1.e+0i
// 6.67428e-11i
// 1E6i
// .25i
// .12345E+5i
//
// Rune literals
//
// A rune literal represents a rune constant, an integer value identifying a
// Unicode code point. A rune literal is expressed as one or more characters
// enclosed in single quotes. Within the quotes, any character may appear
// except single quote and newline. A single quoted character represents the
// Unicode value of the character itself, while multi-character sequences
// beginning with a backslash encode values in various formats.
//
// The simplest form represents the single character within the quotes; since
// QL statements are Unicode characters encoded in UTF-8, multiple
// UTF-8-encoded bytes may represent a single integer value. For instance, the
// literal 'a' holds a single byte representing a literal a, Unicode U+0061,
// value 0x61, while 'ä' holds two bytes (0xc3 0xa4) representing a literal
// a-dieresis, U+00E4, value 0xe4.
//
// Several backslash escapes allow arbitrary values to be encoded as ASCII
// text. There are four ways to represent the integer value as a numeric
// constant: \x followed by exactly two hexadecimal digits; \u followed by
// exactly four hexadecimal digits; \U followed by exactly eight hexadecimal
// digits, and a plain backslash \ followed by exactly three octal digits. In
// each case the value of the literal is the value represented by the digits in
// the corresponding base.
//
// Although these representations all result in an integer, they have different
// valid ranges. Octal escapes must represent a value between 0 and 255
// inclusive. Hexadecimal escapes satisfy this condition by construction. The
// escapes \u and \U represent Unicode code points so within them some values
// are illegal, in particular those above 0x10FFFF and surrogate halves.
//
// After a backslash, certain single-character escapes represent special
// values
//
// \a U+0007 alert or bell
// \b U+0008 backspace
// \f U+000C form feed
// \n U+000A line feed or newline
// \r U+000D carriage return
// \t U+0009 horizontal tab
// \v U+000b vertical tab
// \\ U+005c backslash
// \' U+0027 single quote (valid escape only within rune literals)
// \" U+0022 double quote (valid escape only within string literals)
//
// All other sequences starting with a backslash are illegal inside rune
// literals.
//
// rune_lit = "'" ( unicode_value | byte_value ) "'" .
// unicode_value = unicode_char | little_u_value | big_u_value | escaped_char .
// byte_value = octal_byte_value | hex_byte_value .
// octal_byte_value = `\` octal_digit octal_digit octal_digit .
// hex_byte_value = `\` "x" hex_digit hex_digit .
// little_u_value = `\` "u" hex_digit hex_digit hex_digit hex_digit .
// big_u_value = `\` "U" hex_digit hex_digit hex_digit hex_digit
// hex_digit hex_digit hex_digit hex_digit .
// escaped_char = `\` ( "a" | "b" | "f" | "n" | "r" | "t" | "v" | `\` | "'" | `"` ) .
//
// For example
//
// 'a'
// 'ä'
// '本'
// '\t'
// '\000'
// '\007'
// '\377'
// '\x07'
// '\xff'
// '\u12e4'
// '\U00101234'
// 'aa' // illegal: too many characters
// '\xa' // illegal: too few hexadecimal digits
// '\0' // illegal: too few octal digits
// '\uDFFF' // illegal: surrogate half
// '\U00110000' // illegal: invalid Unicode code point
//
// String literals
//
// A string literal represents a string constant obtained from concatenating a
// sequence of characters. There are two forms: raw string literals and
// interpreted string literals.
//
// Raw string literals are character sequences between back quotes ``. Within
// the quotes, any character is legal except back quote. The value of a raw
// string literal is the string composed of the uninterpreted (implicitly
// UTF-8-encoded) characters between the quotes; in particular, backslashes
// have no special meaning and the string may contain newlines. Carriage
// returns inside raw string literals are discarded from the raw string value.
//
// Interpreted string literals are character sequences between double quotes
// "". The text between the quotes, which may not contain newlines, forms the
// value of the literal, with backslash escapes interpreted as they are in rune
// literals (except that \' is illegal and \" is legal), with the same
// restrictions. The three-digit octal (\nnn) and two-digit hexadecimal (\xnn)
// escapes represent individual bytes of the resulting string; all other
// escapes represent the (possibly multi-byte) UTF-8 encoding of individual
// characters. Thus inside a string literal \377 and \xFF represent a single
// byte of value 0xFF=255, while ÿ, \u00FF, \U000000FF and \xc3\xbf represent
// the two bytes 0xc3 0xbf of the UTF-8 encoding of character U+00FF.
//
// string_lit = raw_string_lit | interpreted_string_lit .
// raw_string_lit = "`" { unicode_char | newline } "`" .
// interpreted_string_lit = `"` { unicode_value | byte_value } `"` .
//
// For example
//
// `abc` // same as "abc"
// `\n
// \n` // same as "\\n\n\\n"
// "\n"
// ""
// "Hello, world!\n"
// "日本語"
// "\u65e5本\U00008a9e"
// "\xff\u00FF"
// "\uD800" // illegal: surrogate half
// "\U00110000" // illegal: invalid Unicode code point
//
// These examples all represent the same string
//
// "日本語" // UTF-8 input text
// `日本語` // UTF-8 input text as a raw literal
// "\u65e5\u672c\u8a9e" // the explicit Unicode code points
// "\U000065e5\U0000672c\U00008a9e" // the explicit Unicode code points
// "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e" // the explicit UTF-8 bytes
//
// If the statement source represents a character as two code points, such as a
// combining form involving an accent and a letter, the result will be an error
// if placed in a rune literal (it is not a single code point), and will appear
// as two code points if placed in a string literal.
//
// QL parameters
//
// Literals are assigned their values from the respective text representation
// at "compile" (parse) time. QL parameters provide the same functionality as
// literals, but their value is assigned at execution time from an expression
// list passed to DB.Run or DB.Execute. Using '?' or '$' is completely
// equivalent.
//
// ql_parameter = ( "?" | "$" ) "1" … "9" { "0" … "9" } .
//
// For example
//
// SELECT DepartmentID
// FROM department
// WHERE DepartmentID == ?1
// ORDER BY DepartmentName;
//
// SELECT employee.LastName
// FROM department, employee
// WHERE department.DepartmentID == $1 && employee.LastName > $2
// ORDER BY DepartmentID;
//
// Constants
//
// Keywords 'false' and 'true' (not case sensitive) represent the two possible
// constant values of type bool (also not case sensitive).
//
// Keyword 'NULL' (not case sensitive) represents an untyped constant which is
// assignable to any type. NULL is distinct from any other value of any type.
//
// Types
//
// A type determines the set of values and operations specific to values of
// that type. A type is specified by a type name.
//
// Type = "bigint" // http://golang.org/pkg/math/big/#Int
// | "bigrat" // http://golang.org/pkg/math/big/#Rat
// | "blob" // []byte
// | "bool"
// | "byte" // alias for uint8
// | "complex128"
// | "complex64"
// | "duration" // http://golang.org/pkg/time/#Duration
// | "float" // alias for float64
// | "float32"
// | "float64"
// | "int" // alias for int64
// | "int16"
// | "int32"
// | "int64"
// | "int8"
// | "rune" // alias for int32
// | "string"
// | "time" // http://golang.org/pkg/time/#Time
// | "uint" // alias for uint64
// | "uint16"
// | "uint32"
// | "uint64"
// | "uint8" .
//
// Named instances of the boolean, numeric, and string types are keywords. The
// names are not case sensitive.
//
// Note: The blob type is exchanged between the back end and the API as []byte.
// On 32 bit platforms this limits the size which the implementation can handle
// to 2G.
//
// Boolean types
//
// A boolean type represents the set of Boolean truth values denoted by the
// predeclared constants true and false. The predeclared boolean type is bool.
//
// Duration type
//
// A duration type represents the elapsed time between two instants as an int64
// nanosecond count. The representation limits the largest representable
// duration to approximately 290 years.
//
// Numeric types
//
// A numeric type represents sets of integer or floating-point values. The
// predeclared architecture-independent numeric types are
//
// uint8 the set of all unsigned 8-bit integers (0 to 255)
// uint16 the set of all unsigned 16-bit integers (0 to 65535)
// uint32 the set of all unsigned 32-bit integers (0 to 4294967295)
// uint64 the set of all unsigned 64-bit integers (0 to 18446744073709551615)
//
// int8 the set of all signed 8-bit integers (-128 to 127)
// int16 the set of all signed 16-bit integers (-32768 to 32767)
// int32 the set of all signed 32-bit integers (-2147483648 to 2147483647)
// int64 the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807)
// duration the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807)
// bigint the set of all integers
//
// bigrat the set of all rational numbers
//
// float32 the set of all IEEE-754 32-bit floating-point numbers
// float64 the set of all IEEE-754 64-bit floating-point numbers
//
// complex64 the set of all complex numbers with float32 real and imaginary parts
// complex128 the set of all complex numbers with float64 real and imaginary parts
//
// byte alias for uint8
// float alias for float64
// int alias for int64
// rune alias for int32
// uint alias for uint64
//
// The value of an n-bit integer is n bits wide and represented using two's
// complement arithmetic.
//
// Conversions are required when different numeric types are mixed in an
// expression or assignment.
//
// String types
//
// A string type represents the set of string values. A string value is a
// (possibly empty) sequence of bytes. The case insensitive keyword for the
// string type is 'string'.
//
// The length of a string (its size in bytes) can be discovered using the
// built-in function len.
//
// Time types
//
// A time type represents an instant in time with nanosecond precision. Each
// time has associated with it a location, consulted when computing the
// presentation form of the time.
//
// Predeclared functions
//
// The following functions are implicitly declared
//
// avg complex contains count date
// day formatTime formatFloat formatInt
// hasPrefix hasSuffix hour hours id
// imag len max min minute
// minutes month nanosecond nanoseconds now
// parseTime real second seconds since
// sum timeIn weekday year yearDay
//
// Expressions
//
// An expression specifies the computation of a value by applying operators and
// functions to operands.
//
// Operands
//
// Operands denote the elementary values in an expression. An operand may be a
// literal, a (possibly qualified) identifier denoting a constant or a function
// or a table/record set column, or a parenthesized expression.
//
// Operand = Literal | QualifiedIdent | "(" Expression ")" .
// Literal = "FALSE" | "NULL" | "TRUE"
// | float_lit | imaginary_lit | int_lit | rune_lit | string_lit
// | ql_parameter .
//
// Qualified identifiers
//
// A qualified identifier is an identifier qualified with a table/record set
// name prefix.
//
// QualifiedIdent = identifier [ "." identifier ] .
//
// For example
//
// invoice.Num // might denote column 'Num' from table 'invoice'
//
// Primary expressions
//
// Primary expression are the operands for unary and binary expressions.
//
// PrimaryExpression = Operand
// | Conversion
// | PrimaryExpression Index
// | PrimaryExpression Slice
// | PrimaryExpression Call .
//
// Call = "(" [ "*" | ExpressionList ] ")" . // * only in count(*).
// Index = "[" Expression "]" .
// Slice = "[" [ Expression ] ":" [ Expression ] "]" .
//
// For example
//
// x
// 2
// (s + ".txt")
// f(3.1415, true)
// s[i : j + 1]
//
// Index expressions
//
// A primary expression of the form
//
// s[x]
//
// denotes the element of a string indexed by x. Its type is byte. The value x
// is called the index. The following rules apply
//
// - The index x must be of integer type except bigint or duration; it is in
// range if 0 <= x < len(s), otherwise it is out of range.
//
// - A constant index must be non-negative and representable by a value of type
// int.
//
// - A constant index must be in range if the string a is a literal.
//
// - If x is out of range at run time, a run-time error occurs.
//
// - s[x] is the byte at index x and the type of s[x] is byte.
//
// If s is NULL or x is NULL then the result is NULL.
//
// Otherwise s[x] is illegal.
//
// Slices
//
// For a string, the primary expression
//
// s[low : high]
//
// constructs a substring. The indices low and high select which elements
// appear in the result. The result has indices starting at 0 and length equal
// to high - low.
//
// For convenience, any of the indices may be omitted. A missing low index
// defaults to zero; a missing high index defaults to the length of the sliced
// operand
//
// s[2:] // same s[2 : len(s)]
// s[:3] // same as s[0 : 3]
// s[:] // same as s[0 : len(s)]
//
// The indices low and high are in range if 0 <= low <= high <= len(a),
// otherwise they are out of range. A constant index must be non-negative and
// representable by a value of type int. If both indices are constant, they
// must satisfy low <= high. If the indices are out of range at run time, a
// run-time error occurs.
//
// Integer values of type bigint or duration cannot be used as indices.
//
// If s is NULL the result is NULL. If low or high is not omitted and is NULL
// then the result is NULL.
//
// Calls
//
// Given an identifier f denoting a predeclared function,
//
// f(a1, a2, … an)
//
// calls f with arguments a1, a2, … an. Arguments are evaluated before the
// function is called. The type of the expression is the result type of f.
//
// complex(x, y)
// len(name)
//
// In a function call, the function value and arguments are evaluated in the
// usual order. After they are evaluated, the parameters of the call are passed
// by value to the function and the called function begins execution. The
// return value of the function is passed by value when the function returns.
//
// Calling an undefined function causes a compile-time error.
//
// Operators
//
// Operators combine operands into expressions.
//
// Expression = Term { ( oror | "OR" ) Term } .
//
// ExpressionList = Expression { "," Expression } [ "," ].
// Factor = PrimaryFactor { ( ge | ">" | le | "<" | neq | eq | "LIKE" ) PrimaryFactor } [ Predicate ] .
// PrimaryFactor = PrimaryTerm { ( "^" | "|" | "-" | "+" ) PrimaryTerm } .
// PrimaryTerm = UnaryExpr { ( andnot | "&" | lsh | rsh | "%" | "/" | "*" ) UnaryExpr } .
// Term = Factor { ( andand | "AND" ) Factor } .
// UnaryExpr = [ "^" | "!" | "-" | "+" ] PrimaryExpression .
//
// Comparisons are discussed elsewhere. For other binary operators, the operand
// types must be identical unless the operation involves shifts or untyped
// constants. For operations involving constants only, see the section on
// constant expressions.
//
// Except for shift operations, if one operand is an untyped constant and the
// other operand is not, the constant is converted to the type of the other
// operand.
//
// The right operand in a shift expression must have unsigned integer type or
// be an untyped constant that can be converted to unsigned integer type. If
// the left operand of a non-constant shift expression is an untyped constant,
// the type of the constant is what it would be if the shift expression were
// replaced by its left operand alone.
//
// Pattern matching
//
// Expressions of the form
//
// expr1 LIKE expr2
//
// yield a boolean value true if expr2, a regular expression, matches expr1
// (see also [6]). Both expression must be of type string. If any one of the
// expressions is NULL the result is NULL.
//
// Predicates
//
// Predicates are special form expressions having a boolean result type.
//
// Expressions of the form
//
// expr IN ( expr1, expr2, expr3, ... ) // case A
//
// expr NOT IN ( expr1, expr2, expr3, ... ) // case B
//
// are equivalent, including NULL handling, to
//
// expr == expr1 || expr == expr2 || expr == expr3 || ... // case A
//
// expr != expr1 && expr != expr2 && expr != expr3 && ... // case B
//
// The types of involved expressions must be comparable as defined in
// "Comparison operators".
//
// Another form of the IN predicate creates the expression list from a result
// of a SelectStmt.
//
// DELETE FROM t WHERE id() IN (SELECT id_t FROM u WHERE inactive_days > 365)
//
// The SelectStmt must select only one column. The produced expression list is
// resource limited by the memory available to the process. NULL values
// produced by the SelectStmt are ignored, but if all records of the SelectStmt
// are NULL the predicate yields NULL. The select statement is evaluated only
// once. If the type of expr is not the same as the type of the field returned
// by the SelectStmt then the set operation yields false. The type of the
// column returned by the SelectStmt must be one of the simple (non blob-like)
// types:
//
// bool
// byte // alias uint8
// complex128
// complex64
// float // alias float64
// float32
// float64
// int // alias int64
// int16
// int32
// int64
// int8
// rune // alias int32
// string
// uint // alias uint64
// uint16
// uint32
// uint64
// uint8
//
// Expressions of the form
//
// expr BETWEEN low AND high // case A
//
// expr NOT BETWEEN low AND high // case B
//
// are equivalent, including NULL handling, to
//
// expr >= low && expr <= high // case A
//
// expr < low || expr > high // case B
//
// The types of involved expressions must be ordered as defined in "Comparison
// operators".
//
// Predicate = (
// [ "NOT" ] (
// "IN" "(" ExpressionList ")"
// | "IN" "(" SelectStmt [ ";" ] ")"
// | "BETWEEN" PrimaryFactor "AND" PrimaryFactor
// )
// | "IS" [ "NOT" ] "NULL"
// ).
//
// Expressions of the form
//
// expr IS NULL // case A
//
// expr IS NOT NULL // case B
//
// yield a boolean value true if expr does not have a specific type (case A) or
// if expr has a specific type (case B). In other cases the result is a boolean
// value false.
//
// Operator precedence
//
// Unary operators have the highest precedence.
//
// There are five precedence levels for binary operators. Multiplication
// operators bind strongest, followed by addition operators, comparison
// operators, && (logical AND), and finally || (logical OR)
//
// Precedence Operator
// 5 * / % << >> & &^
// 4 + - | ^
// 3 == != < <= > >=
// 2 &&
// 1 ||
//
// Binary operators of the same precedence associate from left to right. For
// instance, x / y * z is the same as (x / y) * z.
//
// +x
// 23 + 3*x[i]
// x <= f()
// ^a >> b
// f() || g()
// x == y+1 && z > 0
//
// Note that the operator precedence is reflected explicitly by the grammar.
//
// Arithmetic operators
//
// Arithmetic operators apply to numeric values and yield a result of the same
// type as the first operand. The four standard arithmetic operators (+, -, *,
// /) apply to integer, rational, floating-point, and complex types; + also
// applies to strings; +,- also applies to times. All other arithmetic
// operators apply to integers only.
//
// + sum integers, rationals, floats, complex values, strings
// - difference integers, rationals, floats, complex values, times
// * product integers, rationals, floats, complex values
// / quotient integers, rationals, floats, complex values
// % remainder integers
//
// & bitwise AND integers
// | bitwise OR integers
// ^ bitwise XOR integers
// &^ bit clear (AND NOT) integers
//
// << left shift integer << unsigned integer
// >> right shift integer >> unsigned integer
//
// Strings can be concatenated using the + operator
//
// "hi" + string(c) + " and good bye"
//
// String addition creates a new string by concatenating the operands.
//
// A value of type duration can be added to or subtracted from a value of type time.
//
// now() + duration("1h") // time after 1 hour from now
// duration("1h") + now() // time after 1 hour from now
// now() - duration("1h") // time before 1 hour from now
// duration("1h") - now() // illegal, negative times do not exist
//
// Times can subtracted from each other producing a value of type duration.