@polycode-projects/the-mechanical-code-talker 2.2.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/bin/tmct.mjs +4 -5
  2. package/corpus/LICENSES.json +19 -4
  3. package/corpus/README.md +48 -0
  4. package/corpus/generated/README.md +24 -9
  5. package/corpus/generated/ace-surface-variants.jsonl +4 -1
  6. package/corpus/generated/manifest.json +4 -4
  7. package/corpus/prose/manifest.json +512 -0
  8. package/corpus/prose/sqlite/LICENSE-NOTICE +53 -0
  9. package/corpus/prose/sqlite/arch.txt +213 -0
  10. package/corpus/prose/sqlite/atomiccommit.txt +1117 -0
  11. package/corpus/prose/sqlite/faq.txt +473 -0
  12. package/corpus/prose/sqlite/fileformat.txt +1589 -0
  13. package/corpus/prose/sqlite/lang_createtable.txt +1339 -0
  14. package/corpus/prose/sqlite/lang_insert.txt +580 -0
  15. package/corpus/prose/sqlite/lang_select.txt +3293 -0
  16. package/corpus/prose/sqlite/optoverview.txt +908 -0
  17. package/corpus/prose/sqlite/queryplanner.txt +447 -0
  18. package/corpus/prose/sqlite/transactional.txt +41 -0
  19. package/corpus/prose/sqlite/wal.txt +567 -0
  20. package/corpus/prose/sqlite/whentouse.txt +300 -0
  21. package/corpus/prose/wikipedia/Apple.txt +4 -0
  22. package/corpus/prose/wikipedia/Attempto_Controlled_English.txt +169 -0
  23. package/corpus/prose/wikipedia/Automated_planning_and_scheduling.txt +67 -0
  24. package/corpus/prose/wikipedia/Bee.txt +7 -0
  25. package/corpus/prose/wikipedia/Bird.txt +8 -0
  26. package/corpus/prose/wikipedia/Bone.txt +4 -0
  27. package/corpus/prose/wikipedia/Book.txt +7 -0
  28. package/corpus/prose/wikipedia/Bread.txt +6 -0
  29. package/corpus/prose/wikipedia/Butterfly.txt +6 -0
  30. package/corpus/prose/wikipedia/Car.txt +1 -0
  31. package/corpus/prose/wikipedia/Cat.txt +1 -0
  32. package/corpus/prose/wikipedia/Child.txt +3 -0
  33. package/corpus/prose/wikipedia/City.txt +2 -0
  34. package/corpus/prose/wikipedia/Clock.txt +2 -0
  35. package/corpus/prose/wikipedia/Cooking.txt +1 -0
  36. package/corpus/prose/wikipedia/Description_logic.txt +660 -0
  37. package/corpus/prose/wikipedia/Doctor.txt +6 -0
  38. package/corpus/prose/wikipedia/Dog.txt +4 -0
  39. package/corpus/prose/wikipedia/Eagle.txt +4 -0
  40. package/corpus/prose/wikipedia/Emotion.txt +9 -0
  41. package/corpus/prose/wikipedia/Eye.txt +5 -0
  42. package/corpus/prose/wikipedia/Family.txt +3 -0
  43. package/corpus/prose/wikipedia/Farm.txt +4 -0
  44. package/corpus/prose/wikipedia/Fear.txt +4 -0
  45. package/corpus/prose/wikipedia/First-order_logic.txt +1518 -0
  46. package/corpus/prose/wikipedia/Fish.txt +10 -0
  47. package/corpus/prose/wikipedia/Flower.txt +3 -0
  48. package/corpus/prose/wikipedia/Food.txt +10 -0
  49. package/corpus/prose/wikipedia/Grass.txt +9 -0
  50. package/corpus/prose/wikipedia/Hand.txt +2 -0
  51. package/corpus/prose/wikipedia/Happiness.txt +3 -0
  52. package/corpus/prose/wikipedia/Heart.txt +4 -0
  53. package/corpus/prose/wikipedia/Horse.txt +4 -0
  54. package/corpus/prose/wikipedia/House.txt +6 -0
  55. package/corpus/prose/wikipedia/Human.txt +4 -0
  56. package/corpus/prose/wikipedia/Insect.txt +6 -0
  57. package/corpus/prose/wikipedia/Interactive_fiction.txt +112 -0
  58. package/corpus/prose/wikipedia/Knowledge.txt +5 -0
  59. package/corpus/prose/wikipedia/Knowledge_representation_and_reasoning.txt +87 -0
  60. package/corpus/prose/wikipedia/LICENSE-NOTICE +94 -0
  61. package/corpus/prose/wikipedia/Language.txt +10 -0
  62. package/corpus/prose/wikipedia/Learning.txt +4 -0
  63. package/corpus/prose/wikipedia/Mammal.txt +3 -0
  64. package/corpus/prose/wikipedia/Memory.txt +5 -0
  65. package/corpus/prose/wikipedia/Milk.txt +1 -0
  66. package/corpus/prose/wikipedia/Mountain.txt +1 -0
  67. package/corpus/prose/wikipedia/Natural_language_processing.txt +211 -0
  68. package/corpus/prose/wikipedia/Ostrich.txt +2 -0
  69. package/corpus/prose/wikipedia/Owl.txt +2 -0
  70. package/corpus/prose/wikipedia/Penguin.txt +2 -0
  71. package/corpus/prose/wikipedia/Plant.txt +5 -0
  72. package/corpus/prose/wikipedia/Rain.txt +1 -0
  73. package/corpus/prose/wikipedia/Resource_Description_Framework.txt +184 -0
  74. package/corpus/prose/wikipedia/River.txt +1 -0
  75. package/corpus/prose/wikipedia/School.txt +8 -0
  76. package/corpus/prose/wikipedia/Sea.txt +1 -0
  77. package/corpus/prose/wikipedia/Semantic_Web.txt +114 -0
  78. package/corpus/prose/wikipedia/Semantic_reasoner.txt +29 -0
  79. package/corpus/prose/wikipedia/Snow.txt +5 -0
  80. package/corpus/prose/wikipedia/Sun.txt +5 -0
  81. package/corpus/prose/wikipedia/Teacher.txt +4 -0
  82. package/corpus/prose/wikipedia/Team.txt +3 -0
  83. package/corpus/prose/wikipedia/Text-based_game.txt +17 -0
  84. package/corpus/prose/wikipedia/Tool.txt +4 -0
  85. package/corpus/prose/wikipedia/Tree.txt +7 -0
  86. package/corpus/prose/wikipedia/Weather.txt +4 -0
  87. package/corpus/prose/wikipedia/Web_Ontology_Language.txt +133 -0
  88. package/corpus/prose/wikipedia/Wind.txt +8 -0
  89. package/corpus/prose/wikipedia/Writing.txt +5 -0
  90. package/corpus/wordnet/generate.mjs +6 -7
  91. package/package.json +31 -2
  92. package/src/adapters/corpus/conceptnet.mjs +1 -1
  93. package/src/adapters/graph-build.mjs +3 -3
  94. package/src/adapters/memory/blocks.mjs +2 -2
  95. package/src/adapters/memory/core.mjs +5 -5
  96. package/src/adapters/providers/bootstrap.mjs +1 -1
  97. package/src/adapters/providers/fixture.mjs +1 -1
  98. package/src/adapters/wink-model.mjs +1 -1
  99. package/src/adapters/wordnet-source.mjs +70 -0
  100. package/src/domain/answer-variants.json +1 -1
  101. package/src/domain/ask-vocab.mjs +2 -2
  102. package/src/domain/ask.mjs +4 -4
  103. package/src/domain/codegraph.mjs +3 -3
  104. package/src/domain/corpus-matrix.mjs +87 -0
  105. package/src/domain/grammar/ace.mjs +11 -11
  106. package/src/domain/grammar/lexicon.mjs +3 -3
  107. package/src/domain/inflect.mjs +67 -0
  108. package/src/domain/interpret/fuzzy.mjs +1 -1
  109. package/src/domain/interpret/merge.mjs +1 -1
  110. package/src/domain/interpret/normalize.mjs +1 -1
  111. package/src/domain/licences.mjs +68 -0
  112. package/src/domain/memory/capability.mjs +1 -1
  113. package/src/domain/memory/trust.mjs +2 -2
  114. package/src/domain/persona/codegen.mjs +123 -0
  115. package/src/domain/persona/examples.mjs +26 -0
  116. package/src/domain/persona/tiers.mjs +270 -0
  117. package/src/domain/publish-gate.mjs +41 -0
  118. package/src/domain/router/call-validator.mjs +1 -1
  119. package/src/domain/router/drive.mjs +3 -4
  120. package/src/domain/router/registry.mjs +12 -13
  121. package/src/domain/router/resolver.mjs +18 -5
  122. package/src/domain/router/results.mjs +3 -3
  123. package/src/domain/router/taught.mjs +4 -3
  124. package/src/domain/schemaorg/turtle.mjs +25 -0
  125. package/src/domain/semcor/parse.mjs +87 -0
  126. package/src/domain/syllogise.mjs +6 -6
  127. package/src/domain/version-stamp.mjs +36 -0
  128. package/src/domain/wordnet/yaml.mjs +133 -0
  129. package/src/services/chat-session.mjs +2 -2
  130. package/src/services/chat.mjs +2 -2
  131. package/src/services/cli-args.mjs +4 -4
  132. package/src/services/finish.mjs +1 -1
  133. package/src/services/ledger-viz.mjs +2 -3
  134. package/src/services/sessions.mjs +4 -4
  135. package/src/services/viz-theme.mjs +3 -4
  136. package/src/surfaces/web/memory-ask-browser.bundle.js +1 -18
  137. package/src/domain/router/guardrail.mjs +0 -116
@@ -0,0 +1,3293 @@
1
+ SELECT
2
+ Small. Fast. Reliable.
3
+ Choose any three.
4
+ Home
5
+ Menu
6
+ About
7
+ Documentation
8
+ Download
9
+ License
10
+ Support
11
+ Purchase
12
+ Search
13
+ About
14
+ Documentation
15
+ Download
16
+ Support
17
+ Purchase
18
+ Search Documentation
19
+ Search Changelog
20
+ SELECT
21
+ Table Of Contents
22
+ 1. Overview
23
+ 2. Simple Select Processing
24
+ 2.1. Determination of input data (FROM clause processing)
25
+ 2.2. Special handling of CROSS JOIN.
26
+ 2.3. WHERE clause filtering.
27
+ 2.4. Generation of the set of result rows
28
+ 2.5. Bare columns in an aggregate query
29
+ 2.5.1. Notes
30
+ 2.6. Removal of duplicate rows (DISTINCT processing)
31
+ 3. Compound Select Statements
32
+ 4. The ORDER BY clause
33
+ 5. The LIMIT clause
34
+ 6. The VALUES clause
35
+ 7. The WITH Clause
36
+ 8. Table-valued Functions In The FROM Clause
37
+ 9. Deviations From Standard SQL
38
+ 9.1. Strange JOIN names
39
+ 9.2. Flexible join syntax
40
+ 9.3. Precedence of comma-joins and CROSS JOIN
41
+ 1. Overview
42
+ select-stmt:
43
+ hide
44
+ WITH
45
+ RECURSIVE
46
+ common-table-expression
47
+ ,
48
+ SELECT
49
+ DISTINCT
50
+ result-column
51
+ ,
52
+ ALL
53
+ FROM
54
+ table-or-subquery
55
+ join-clause
56
+ ,
57
+ WHERE
58
+ expr
59
+ GROUP
60
+ BY
61
+ expr
62
+ HAVING
63
+ expr
64
+ ,
65
+ WINDOW
66
+ window-name
67
+ AS
68
+ window-defn
69
+ ,
70
+ VALUES
71
+ (
72
+ expr
73
+ )
74
+ ,
75
+ ,
76
+ compound-operator
77
+ select-core
78
+ ORDER
79
+ BY
80
+ LIMIT
81
+ expr
82
+ ordering-term
83
+ ,
84
+ OFFSET
85
+ expr
86
+ ,
87
+ expr
88
+ common-table-expression:
89
+ show
90
+ table-name
91
+ (
92
+ column-name
93
+ )
94
+ AS
95
+ NOT
96
+ MATERIALIZED
97
+ (
98
+ select-stmt
99
+ )
100
+ ,
101
+ compound-operator:
102
+ show
103
+ UNION
104
+ UNION
105
+ INTERSECT
106
+ EXCEPT
107
+ ALL
108
+ expr:
109
+ show
110
+ literal-value
111
+ bind-parameter
112
+ schema-name
113
+ .
114
+ table-name
115
+ .
116
+ column-name
117
+ unary-operator
118
+ expr
119
+ expr
120
+ binary-operator
121
+ expr
122
+ function-name
123
+ (
124
+ function-arguments
125
+ )
126
+ filter-clause
127
+ over-clause
128
+ (
129
+ expr
130
+ )
131
+ ,
132
+ CAST
133
+ (
134
+ expr
135
+ AS
136
+ type-name
137
+ )
138
+ expr
139
+ COLLATE
140
+ collation-name
141
+ expr
142
+ NOT
143
+ LIKE
144
+ GLOB
145
+ REGEXP
146
+ MATCH
147
+ expr
148
+ expr
149
+ ESCAPE
150
+ expr
151
+ expr
152
+ ISNULL
153
+ NOTNULL
154
+ NOT
155
+ NULL
156
+ expr
157
+ IS
158
+ NOT
159
+ DISTINCT
160
+ FROM
161
+ expr
162
+ expr
163
+ NOT
164
+ BETWEEN
165
+ expr
166
+ AND
167
+ expr
168
+ expr
169
+ NOT
170
+ IN
171
+ (
172
+ select-stmt
173
+ )
174
+ expr
175
+ ,
176
+ schema-name
177
+ .
178
+ table-function
179
+ (
180
+ expr
181
+ )
182
+ table-name
183
+ ,
184
+ NOT
185
+ EXISTS
186
+ (
187
+ select-stmt
188
+ )
189
+ CASE
190
+ expr
191
+ WHEN
192
+ expr
193
+ THEN
194
+ expr
195
+ ELSE
196
+ expr
197
+ END
198
+ raise-function
199
+ filter-clause:
200
+ show
201
+ FILTER
202
+ (
203
+ WHERE
204
+ expr
205
+ )
206
+ function-arguments:
207
+ show
208
+ DISTINCT
209
+ expr
210
+ ,
211
+ *
212
+ ORDER
213
+ BY
214
+ ordering-term
215
+ ,
216
+ literal-value:
217
+ show
218
+ CURRENT_TIMESTAMP
219
+ numeric-literal
220
+ string-literal
221
+ blob-literal
222
+ NULL
223
+ TRUE
224
+ FALSE
225
+ CURRENT_TIME
226
+ CURRENT_DATE
227
+ over-clause:
228
+ show
229
+ OVER
230
+ window-name
231
+ (
232
+ base-window-name
233
+ PARTITION
234
+ BY
235
+ expr
236
+ ,
237
+ ORDER
238
+ BY
239
+ ordering-term
240
+ ,
241
+ frame-spec
242
+ )
243
+ frame-spec:
244
+ show
245
+ GROUPS
246
+ BETWEEN
247
+ UNBOUNDED
248
+ PRECEDING
249
+ AND
250
+ UNBOUNDED
251
+ FOLLOWING
252
+ RANGE
253
+ ROWS
254
+ UNBOUNDED
255
+ PRECEDING
256
+ expr
257
+ PRECEDING
258
+ CURRENT
259
+ ROW
260
+ expr
261
+ PRECEDING
262
+ CURRENT
263
+ ROW
264
+ expr
265
+ FOLLOWING
266
+ expr
267
+ PRECEDING
268
+ CURRENT
269
+ ROW
270
+ expr
271
+ FOLLOWING
272
+ EXCLUDE
273
+ CURRENT
274
+ ROW
275
+ EXCLUDE
276
+ GROUP
277
+ EXCLUDE
278
+ TIES
279
+ EXCLUDE
280
+ NO
281
+ OTHERS
282
+ raise-function:
283
+ show
284
+ RAISE
285
+ (
286
+ ROLLBACK
287
+ ,
288
+ expr
289
+ )
290
+ IGNORE
291
+ ABORT
292
+ FAIL
293
+ type-name:
294
+ show
295
+ name
296
+ (
297
+ signed-number
298
+ ,
299
+ signed-number
300
+ )
301
+ (
302
+ signed-number
303
+ )
304
+ signed-number:
305
+ show
306
+ +
307
+ numeric-literal
308
+ -
309
+ join-clause:
310
+ show
311
+ table-or-subquery
312
+ join-operator
313
+ table-or-subquery
314
+ join-constraint
315
+ join-constraint:
316
+ show
317
+ USING
318
+ (
319
+ column-name
320
+ )
321
+ ,
322
+ ON
323
+ expr
324
+ join-operator:
325
+ show
326
+ NATURAL
327
+ LEFT
328
+ OUTER
329
+ JOIN
330
+ ,
331
+ RIGHT
332
+ FULL
333
+ INNER
334
+ CROSS
335
+ ordering-term:
336
+ show
337
+ expr
338
+ COLLATE
339
+ collation-name
340
+ DESC
341
+ ASC
342
+ NULLS
343
+ FIRST
344
+ NULLS
345
+ LAST
346
+ result-column:
347
+ show
348
+ expr
349
+ AS
350
+ column-alias
351
+ *
352
+ table-name
353
+ .
354
+ *
355
+ table-or-subquery:
356
+ show
357
+ schema-name
358
+ .
359
+ table-name
360
+ AS
361
+ table-alias
362
+ INDEXED
363
+ BY
364
+ index-name
365
+ NOT
366
+ INDEXED
367
+ table-function-name
368
+ (
369
+ expr
370
+ )
371
+ ,
372
+ AS
373
+ table-alias
374
+ (
375
+ select-stmt
376
+ )
377
+ (
378
+ table-or-subquery
379
+ )
380
+ ,
381
+ join-clause
382
+ window-defn:
383
+ show
384
+ (
385
+ base-window-name
386
+ PARTITION
387
+ BY
388
+ expr
389
+ ,
390
+ ORDER
391
+ BY
392
+ ordering-term
393
+ ,
394
+ frame-spec
395
+ )
396
+ frame-spec:
397
+ show
398
+ GROUPS
399
+ BETWEEN
400
+ UNBOUNDED
401
+ PRECEDING
402
+ AND
403
+ UNBOUNDED
404
+ FOLLOWING
405
+ RANGE
406
+ ROWS
407
+ UNBOUNDED
408
+ PRECEDING
409
+ expr
410
+ PRECEDING
411
+ CURRENT
412
+ ROW
413
+ expr
414
+ PRECEDING
415
+ CURRENT
416
+ ROW
417
+ expr
418
+ FOLLOWING
419
+ expr
420
+ PRECEDING
421
+ CURRENT
422
+ ROW
423
+ expr
424
+ FOLLOWING
425
+ EXCLUDE
426
+ CURRENT
427
+ ROW
428
+ EXCLUDE
429
+ GROUP
430
+ EXCLUDE
431
+ TIES
432
+ EXCLUDE
433
+ NO
434
+ OTHERS
435
+ The SELECT statement is used to query the database. The
436
+ result of a SELECT is zero or more rows of data where each row
437
+ has a fixed number of columns. A SELECT statement does not make
438
+ any changes to the database.
439
+ The " select-stmt " syntax diagram above attempts to show as much of the
440
+ SELECT statement syntax as possible in a single diagram, because some readers
441
+ find that helpful. The following " factored-select-stmt " is an alternative
442
+ syntax diagrams that expresses the same syntax but tries to break the syntax
443
+ down into smaller chunks.
444
+ factored-select-stmt:
445
+ show
446
+ WITH
447
+ RECURSIVE
448
+ common-table-expression
449
+ ,
450
+ select-core
451
+ ORDER
452
+ BY
453
+ LIMIT
454
+ expr
455
+ compound-operator
456
+ ordering-term
457
+ ,
458
+ OFFSET
459
+ expr
460
+ ,
461
+ expr
462
+ common-table-expression:
463
+ show
464
+ table-name
465
+ (
466
+ column-name
467
+ )
468
+ AS
469
+ NOT
470
+ MATERIALIZED
471
+ (
472
+ select-stmt
473
+ )
474
+ ,
475
+ select-stmt:
476
+ show
477
+ WITH
478
+ RECURSIVE
479
+ common-table-expression
480
+ ,
481
+ SELECT
482
+ DISTINCT
483
+ result-column
484
+ ,
485
+ ALL
486
+ FROM
487
+ table-or-subquery
488
+ join-clause
489
+ ,
490
+ WHERE
491
+ expr
492
+ GROUP
493
+ BY
494
+ expr
495
+ HAVING
496
+ expr
497
+ ,
498
+ WINDOW
499
+ window-name
500
+ AS
501
+ window-defn
502
+ ,
503
+ VALUES
504
+ (
505
+ expr
506
+ )
507
+ ,
508
+ ,
509
+ compound-operator
510
+ select-core
511
+ ORDER
512
+ BY
513
+ LIMIT
514
+ expr
515
+ ordering-term
516
+ ,
517
+ OFFSET
518
+ expr
519
+ ,
520
+ expr
521
+ join-clause:
522
+ show
523
+ table-or-subquery
524
+ join-operator
525
+ table-or-subquery
526
+ join-constraint
527
+ join-constraint:
528
+ show
529
+ USING
530
+ (
531
+ column-name
532
+ )
533
+ ,
534
+ ON
535
+ expr
536
+ join-operator:
537
+ show
538
+ NATURAL
539
+ LEFT
540
+ OUTER
541
+ JOIN
542
+ ,
543
+ RIGHT
544
+ FULL
545
+ INNER
546
+ CROSS
547
+ result-column:
548
+ show
549
+ expr
550
+ AS
551
+ column-alias
552
+ *
553
+ table-name
554
+ .
555
+ *
556
+ table-or-subquery:
557
+ show
558
+ schema-name
559
+ .
560
+ table-name
561
+ AS
562
+ table-alias
563
+ INDEXED
564
+ BY
565
+ index-name
566
+ NOT
567
+ INDEXED
568
+ table-function-name
569
+ (
570
+ expr
571
+ )
572
+ ,
573
+ AS
574
+ table-alias
575
+ (
576
+ select-stmt
577
+ )
578
+ (
579
+ table-or-subquery
580
+ )
581
+ ,
582
+ join-clause
583
+ window-defn:
584
+ show
585
+ (
586
+ base-window-name
587
+ PARTITION
588
+ BY
589
+ expr
590
+ ,
591
+ ORDER
592
+ BY
593
+ ordering-term
594
+ ,
595
+ frame-spec
596
+ )
597
+ frame-spec:
598
+ show
599
+ GROUPS
600
+ BETWEEN
601
+ UNBOUNDED
602
+ PRECEDING
603
+ AND
604
+ UNBOUNDED
605
+ FOLLOWING
606
+ RANGE
607
+ ROWS
608
+ UNBOUNDED
609
+ PRECEDING
610
+ expr
611
+ PRECEDING
612
+ CURRENT
613
+ ROW
614
+ expr
615
+ PRECEDING
616
+ CURRENT
617
+ ROW
618
+ expr
619
+ FOLLOWING
620
+ expr
621
+ PRECEDING
622
+ CURRENT
623
+ ROW
624
+ expr
625
+ FOLLOWING
626
+ EXCLUDE
627
+ CURRENT
628
+ ROW
629
+ EXCLUDE
630
+ GROUP
631
+ EXCLUDE
632
+ TIES
633
+ EXCLUDE
634
+ NO
635
+ OTHERS
636
+ compound-operator:
637
+ show
638
+ UNION
639
+ UNION
640
+ INTERSECT
641
+ EXCEPT
642
+ ALL
643
+ expr:
644
+ show
645
+ literal-value
646
+ bind-parameter
647
+ schema-name
648
+ .
649
+ table-name
650
+ .
651
+ column-name
652
+ unary-operator
653
+ expr
654
+ expr
655
+ binary-operator
656
+ expr
657
+ function-name
658
+ (
659
+ function-arguments
660
+ )
661
+ filter-clause
662
+ over-clause
663
+ (
664
+ expr
665
+ )
666
+ ,
667
+ CAST
668
+ (
669
+ expr
670
+ AS
671
+ type-name
672
+ )
673
+ expr
674
+ COLLATE
675
+ collation-name
676
+ expr
677
+ NOT
678
+ LIKE
679
+ GLOB
680
+ REGEXP
681
+ MATCH
682
+ expr
683
+ expr
684
+ ESCAPE
685
+ expr
686
+ expr
687
+ ISNULL
688
+ NOTNULL
689
+ NOT
690
+ NULL
691
+ expr
692
+ IS
693
+ NOT
694
+ DISTINCT
695
+ FROM
696
+ expr
697
+ expr
698
+ NOT
699
+ BETWEEN
700
+ expr
701
+ AND
702
+ expr
703
+ expr
704
+ NOT
705
+ IN
706
+ (
707
+ select-stmt
708
+ )
709
+ expr
710
+ ,
711
+ schema-name
712
+ .
713
+ table-function
714
+ (
715
+ expr
716
+ )
717
+ table-name
718
+ ,
719
+ NOT
720
+ EXISTS
721
+ (
722
+ select-stmt
723
+ )
724
+ CASE
725
+ expr
726
+ WHEN
727
+ expr
728
+ THEN
729
+ expr
730
+ ELSE
731
+ expr
732
+ END
733
+ raise-function
734
+ filter-clause:
735
+ show
736
+ FILTER
737
+ (
738
+ WHERE
739
+ expr
740
+ )
741
+ function-arguments:
742
+ show
743
+ DISTINCT
744
+ expr
745
+ ,
746
+ *
747
+ ORDER
748
+ BY
749
+ ordering-term
750
+ ,
751
+ literal-value:
752
+ show
753
+ CURRENT_TIMESTAMP
754
+ numeric-literal
755
+ string-literal
756
+ blob-literal
757
+ NULL
758
+ TRUE
759
+ FALSE
760
+ CURRENT_TIME
761
+ CURRENT_DATE
762
+ over-clause:
763
+ show
764
+ OVER
765
+ window-name
766
+ (
767
+ base-window-name
768
+ PARTITION
769
+ BY
770
+ expr
771
+ ,
772
+ ORDER
773
+ BY
774
+ ordering-term
775
+ ,
776
+ frame-spec
777
+ )
778
+ frame-spec:
779
+ show
780
+ GROUPS
781
+ BETWEEN
782
+ UNBOUNDED
783
+ PRECEDING
784
+ AND
785
+ UNBOUNDED
786
+ FOLLOWING
787
+ RANGE
788
+ ROWS
789
+ UNBOUNDED
790
+ PRECEDING
791
+ expr
792
+ PRECEDING
793
+ CURRENT
794
+ ROW
795
+ expr
796
+ PRECEDING
797
+ CURRENT
798
+ ROW
799
+ expr
800
+ FOLLOWING
801
+ expr
802
+ PRECEDING
803
+ CURRENT
804
+ ROW
805
+ expr
806
+ FOLLOWING
807
+ EXCLUDE
808
+ CURRENT
809
+ ROW
810
+ EXCLUDE
811
+ GROUP
812
+ EXCLUDE
813
+ TIES
814
+ EXCLUDE
815
+ NO
816
+ OTHERS
817
+ raise-function:
818
+ show
819
+ RAISE
820
+ (
821
+ ROLLBACK
822
+ ,
823
+ expr
824
+ )
825
+ IGNORE
826
+ ABORT
827
+ FAIL
828
+ select-stmt:
829
+ show
830
+ WITH
831
+ RECURSIVE
832
+ common-table-expression
833
+ ,
834
+ SELECT
835
+ DISTINCT
836
+ result-column
837
+ ,
838
+ ALL
839
+ FROM
840
+ table-or-subquery
841
+ join-clause
842
+ ,
843
+ WHERE
844
+ expr
845
+ GROUP
846
+ BY
847
+ expr
848
+ HAVING
849
+ expr
850
+ ,
851
+ WINDOW
852
+ window-name
853
+ AS
854
+ window-defn
855
+ ,
856
+ VALUES
857
+ (
858
+ expr
859
+ )
860
+ ,
861
+ ,
862
+ compound-operator
863
+ select-core
864
+ ORDER
865
+ BY
866
+ LIMIT
867
+ expr
868
+ ordering-term
869
+ ,
870
+ OFFSET
871
+ expr
872
+ ,
873
+ expr
874
+ join-clause:
875
+ show
876
+ table-or-subquery
877
+ join-operator
878
+ table-or-subquery
879
+ join-constraint
880
+ join-constraint:
881
+ show
882
+ USING
883
+ (
884
+ column-name
885
+ )
886
+ ,
887
+ ON
888
+ expr
889
+ join-operator:
890
+ show
891
+ NATURAL
892
+ LEFT
893
+ OUTER
894
+ JOIN
895
+ ,
896
+ RIGHT
897
+ FULL
898
+ INNER
899
+ CROSS
900
+ result-column:
901
+ show
902
+ expr
903
+ AS
904
+ column-alias
905
+ *
906
+ table-name
907
+ .
908
+ *
909
+ table-or-subquery:
910
+ show
911
+ schema-name
912
+ .
913
+ table-name
914
+ AS
915
+ table-alias
916
+ INDEXED
917
+ BY
918
+ index-name
919
+ NOT
920
+ INDEXED
921
+ table-function-name
922
+ (
923
+ expr
924
+ )
925
+ ,
926
+ AS
927
+ table-alias
928
+ (
929
+ select-stmt
930
+ )
931
+ (
932
+ table-or-subquery
933
+ )
934
+ ,
935
+ join-clause
936
+ window-defn:
937
+ show
938
+ (
939
+ base-window-name
940
+ PARTITION
941
+ BY
942
+ expr
943
+ ,
944
+ ORDER
945
+ BY
946
+ ordering-term
947
+ ,
948
+ frame-spec
949
+ )
950
+ frame-spec:
951
+ show
952
+ GROUPS
953
+ BETWEEN
954
+ UNBOUNDED
955
+ PRECEDING
956
+ AND
957
+ UNBOUNDED
958
+ FOLLOWING
959
+ RANGE
960
+ ROWS
961
+ UNBOUNDED
962
+ PRECEDING
963
+ expr
964
+ PRECEDING
965
+ CURRENT
966
+ ROW
967
+ expr
968
+ PRECEDING
969
+ CURRENT
970
+ ROW
971
+ expr
972
+ FOLLOWING
973
+ expr
974
+ PRECEDING
975
+ CURRENT
976
+ ROW
977
+ expr
978
+ FOLLOWING
979
+ EXCLUDE
980
+ CURRENT
981
+ ROW
982
+ EXCLUDE
983
+ GROUP
984
+ EXCLUDE
985
+ TIES
986
+ EXCLUDE
987
+ NO
988
+ OTHERS
989
+ type-name:
990
+ show
991
+ name
992
+ (
993
+ signed-number
994
+ ,
995
+ signed-number
996
+ )
997
+ (
998
+ signed-number
999
+ )
1000
+ signed-number:
1001
+ show
1002
+ +
1003
+ numeric-literal
1004
+ -
1005
+ ordering-term:
1006
+ show
1007
+ expr
1008
+ COLLATE
1009
+ collation-name
1010
+ DESC
1011
+ ASC
1012
+ NULLS
1013
+ FIRST
1014
+ NULLS
1015
+ LAST
1016
+ select-core:
1017
+ show
1018
+ SELECT
1019
+ DISTINCT
1020
+ result-column
1021
+ ,
1022
+ ALL
1023
+ FROM
1024
+ table-or-subquery
1025
+ join-clause
1026
+ ,
1027
+ WHERE
1028
+ expr
1029
+ GROUP
1030
+ BY
1031
+ expr
1032
+ HAVING
1033
+ expr
1034
+ ,
1035
+ WINDOW
1036
+ window-name
1037
+ AS
1038
+ window-defn
1039
+ ,
1040
+ VALUES
1041
+ (
1042
+ expr
1043
+ )
1044
+ ,
1045
+ ,
1046
+ join-clause:
1047
+ show
1048
+ table-or-subquery
1049
+ join-operator
1050
+ table-or-subquery
1051
+ join-constraint
1052
+ join-constraint:
1053
+ show
1054
+ USING
1055
+ (
1056
+ column-name
1057
+ )
1058
+ ,
1059
+ ON
1060
+ expr
1061
+ join-operator:
1062
+ show
1063
+ NATURAL
1064
+ LEFT
1065
+ OUTER
1066
+ JOIN
1067
+ ,
1068
+ RIGHT
1069
+ FULL
1070
+ INNER
1071
+ CROSS
1072
+ result-column:
1073
+ show
1074
+ expr
1075
+ AS
1076
+ column-alias
1077
+ *
1078
+ table-name
1079
+ .
1080
+ *
1081
+ table-or-subquery:
1082
+ show
1083
+ schema-name
1084
+ .
1085
+ table-name
1086
+ AS
1087
+ table-alias
1088
+ INDEXED
1089
+ BY
1090
+ index-name
1091
+ NOT
1092
+ INDEXED
1093
+ table-function-name
1094
+ (
1095
+ expr
1096
+ )
1097
+ ,
1098
+ AS
1099
+ table-alias
1100
+ (
1101
+ select-stmt
1102
+ )
1103
+ (
1104
+ table-or-subquery
1105
+ )
1106
+ ,
1107
+ join-clause
1108
+ select-stmt:
1109
+ show
1110
+ WITH
1111
+ RECURSIVE
1112
+ common-table-expression
1113
+ ,
1114
+ SELECT
1115
+ DISTINCT
1116
+ result-column
1117
+ ,
1118
+ ALL
1119
+ FROM
1120
+ table-or-subquery
1121
+ join-clause
1122
+ ,
1123
+ WHERE
1124
+ expr
1125
+ GROUP
1126
+ BY
1127
+ expr
1128
+ HAVING
1129
+ expr
1130
+ ,
1131
+ WINDOW
1132
+ window-name
1133
+ AS
1134
+ window-defn
1135
+ ,
1136
+ VALUES
1137
+ (
1138
+ expr
1139
+ )
1140
+ ,
1141
+ ,
1142
+ compound-operator
1143
+ select-core
1144
+ ORDER
1145
+ BY
1146
+ LIMIT
1147
+ expr
1148
+ ordering-term
1149
+ ,
1150
+ OFFSET
1151
+ expr
1152
+ ,
1153
+ expr
1154
+ window-defn:
1155
+ show
1156
+ (
1157
+ base-window-name
1158
+ PARTITION
1159
+ BY
1160
+ expr
1161
+ ,
1162
+ ORDER
1163
+ BY
1164
+ ordering-term
1165
+ ,
1166
+ frame-spec
1167
+ )
1168
+ frame-spec:
1169
+ show
1170
+ GROUPS
1171
+ BETWEEN
1172
+ UNBOUNDED
1173
+ PRECEDING
1174
+ AND
1175
+ UNBOUNDED
1176
+ FOLLOWING
1177
+ RANGE
1178
+ ROWS
1179
+ UNBOUNDED
1180
+ PRECEDING
1181
+ expr
1182
+ PRECEDING
1183
+ CURRENT
1184
+ ROW
1185
+ expr
1186
+ PRECEDING
1187
+ CURRENT
1188
+ ROW
1189
+ expr
1190
+ FOLLOWING
1191
+ expr
1192
+ PRECEDING
1193
+ CURRENT
1194
+ ROW
1195
+ expr
1196
+ FOLLOWING
1197
+ EXCLUDE
1198
+ CURRENT
1199
+ ROW
1200
+ EXCLUDE
1201
+ GROUP
1202
+ EXCLUDE
1203
+ TIES
1204
+ EXCLUDE
1205
+ NO
1206
+ OTHERS
1207
+ Note that there are paths through the syntax diagrams that
1208
+ are not allowed in practice. Some examples:
1209
+ A VALUES clause can be the first element in a compound SELECT
1210
+ that uses a WITH clause, but a simple SELECT that consists of
1211
+ just a VALUES clause cannot be preceded by a WITH clause.
1212
+ The WITH clause must occur on the first SELECT of a compound SELECT .
1213
+ It cannot follow a compound-operator .
1214
+ These and other similar syntax restrictions are described in the text.
1215
+ The SELECT statement is the most complicated command in the SQL language.
1216
+ To make the description easier to follow, some of the passages below describe
1217
+ the way the data returned by a SELECT statement is determined as a series of
1218
+ steps. It is important to keep in mind that this is purely illustrative -
1219
+ in practice neither SQLite nor any other SQL engine is required to follow
1220
+ this or any other specific process.
1221
+ 2. Simple Select Processing
1222
+ The core of a SELECT statement is a "simple SELECT" shown by the
1223
+ select-core and simple-select-stmt syntax diagrams below.
1224
+ In practice, most SELECT statements are simple SELECT statements.
1225
+ simple-select-stmt:
1226
+ hide
1227
+ WITH
1228
+ RECURSIVE
1229
+ common-table-expression
1230
+ ,
1231
+ select-core
1232
+ ORDER
1233
+ BY
1234
+ LIMIT
1235
+ expr
1236
+ ordering-term
1237
+ ,
1238
+ OFFSET
1239
+ expr
1240
+ ,
1241
+ expr
1242
+ common-table-expression:
1243
+ show
1244
+ table-name
1245
+ (
1246
+ column-name
1247
+ )
1248
+ AS
1249
+ NOT
1250
+ MATERIALIZED
1251
+ (
1252
+ select-stmt
1253
+ )
1254
+ ,
1255
+ select-stmt:
1256
+ show
1257
+ WITH
1258
+ RECURSIVE
1259
+ common-table-expression
1260
+ ,
1261
+ SELECT
1262
+ DISTINCT
1263
+ result-column
1264
+ ,
1265
+ ALL
1266
+ FROM
1267
+ table-or-subquery
1268
+ join-clause
1269
+ ,
1270
+ WHERE
1271
+ expr
1272
+ GROUP
1273
+ BY
1274
+ expr
1275
+ HAVING
1276
+ expr
1277
+ ,
1278
+ WINDOW
1279
+ window-name
1280
+ AS
1281
+ window-defn
1282
+ ,
1283
+ VALUES
1284
+ (
1285
+ expr
1286
+ )
1287
+ ,
1288
+ ,
1289
+ compound-operator
1290
+ select-core
1291
+ ORDER
1292
+ BY
1293
+ LIMIT
1294
+ expr
1295
+ ordering-term
1296
+ ,
1297
+ OFFSET
1298
+ expr
1299
+ ,
1300
+ expr
1301
+ compound-operator:
1302
+ show
1303
+ UNION
1304
+ UNION
1305
+ INTERSECT
1306
+ EXCEPT
1307
+ ALL
1308
+ join-clause:
1309
+ show
1310
+ table-or-subquery
1311
+ join-operator
1312
+ table-or-subquery
1313
+ join-constraint
1314
+ join-constraint:
1315
+ show
1316
+ USING
1317
+ (
1318
+ column-name
1319
+ )
1320
+ ,
1321
+ ON
1322
+ expr
1323
+ join-operator:
1324
+ show
1325
+ NATURAL
1326
+ LEFT
1327
+ OUTER
1328
+ JOIN
1329
+ ,
1330
+ RIGHT
1331
+ FULL
1332
+ INNER
1333
+ CROSS
1334
+ result-column:
1335
+ show
1336
+ expr
1337
+ AS
1338
+ column-alias
1339
+ *
1340
+ table-name
1341
+ .
1342
+ *
1343
+ table-or-subquery:
1344
+ show
1345
+ schema-name
1346
+ .
1347
+ table-name
1348
+ AS
1349
+ table-alias
1350
+ INDEXED
1351
+ BY
1352
+ index-name
1353
+ NOT
1354
+ INDEXED
1355
+ table-function-name
1356
+ (
1357
+ expr
1358
+ )
1359
+ ,
1360
+ AS
1361
+ table-alias
1362
+ (
1363
+ select-stmt
1364
+ )
1365
+ (
1366
+ table-or-subquery
1367
+ )
1368
+ ,
1369
+ join-clause
1370
+ window-defn:
1371
+ show
1372
+ (
1373
+ base-window-name
1374
+ PARTITION
1375
+ BY
1376
+ expr
1377
+ ,
1378
+ ORDER
1379
+ BY
1380
+ ordering-term
1381
+ ,
1382
+ frame-spec
1383
+ )
1384
+ frame-spec:
1385
+ show
1386
+ GROUPS
1387
+ BETWEEN
1388
+ UNBOUNDED
1389
+ PRECEDING
1390
+ AND
1391
+ UNBOUNDED
1392
+ FOLLOWING
1393
+ RANGE
1394
+ ROWS
1395
+ UNBOUNDED
1396
+ PRECEDING
1397
+ expr
1398
+ PRECEDING
1399
+ CURRENT
1400
+ ROW
1401
+ expr
1402
+ PRECEDING
1403
+ CURRENT
1404
+ ROW
1405
+ expr
1406
+ FOLLOWING
1407
+ expr
1408
+ PRECEDING
1409
+ CURRENT
1410
+ ROW
1411
+ expr
1412
+ FOLLOWING
1413
+ EXCLUDE
1414
+ CURRENT
1415
+ ROW
1416
+ EXCLUDE
1417
+ GROUP
1418
+ EXCLUDE
1419
+ TIES
1420
+ EXCLUDE
1421
+ NO
1422
+ OTHERS
1423
+ expr:
1424
+ show
1425
+ literal-value
1426
+ bind-parameter
1427
+ schema-name
1428
+ .
1429
+ table-name
1430
+ .
1431
+ column-name
1432
+ unary-operator
1433
+ expr
1434
+ expr
1435
+ binary-operator
1436
+ expr
1437
+ function-name
1438
+ (
1439
+ function-arguments
1440
+ )
1441
+ filter-clause
1442
+ over-clause
1443
+ (
1444
+ expr
1445
+ )
1446
+ ,
1447
+ CAST
1448
+ (
1449
+ expr
1450
+ AS
1451
+ type-name
1452
+ )
1453
+ expr
1454
+ COLLATE
1455
+ collation-name
1456
+ expr
1457
+ NOT
1458
+ LIKE
1459
+ GLOB
1460
+ REGEXP
1461
+ MATCH
1462
+ expr
1463
+ expr
1464
+ ESCAPE
1465
+ expr
1466
+ expr
1467
+ ISNULL
1468
+ NOTNULL
1469
+ NOT
1470
+ NULL
1471
+ expr
1472
+ IS
1473
+ NOT
1474
+ DISTINCT
1475
+ FROM
1476
+ expr
1477
+ expr
1478
+ NOT
1479
+ BETWEEN
1480
+ expr
1481
+ AND
1482
+ expr
1483
+ expr
1484
+ NOT
1485
+ IN
1486
+ (
1487
+ select-stmt
1488
+ )
1489
+ expr
1490
+ ,
1491
+ schema-name
1492
+ .
1493
+ table-function
1494
+ (
1495
+ expr
1496
+ )
1497
+ table-name
1498
+ ,
1499
+ NOT
1500
+ EXISTS
1501
+ (
1502
+ select-stmt
1503
+ )
1504
+ CASE
1505
+ expr
1506
+ WHEN
1507
+ expr
1508
+ THEN
1509
+ expr
1510
+ ELSE
1511
+ expr
1512
+ END
1513
+ raise-function
1514
+ filter-clause:
1515
+ show
1516
+ FILTER
1517
+ (
1518
+ WHERE
1519
+ expr
1520
+ )
1521
+ function-arguments:
1522
+ show
1523
+ DISTINCT
1524
+ expr
1525
+ ,
1526
+ *
1527
+ ORDER
1528
+ BY
1529
+ ordering-term
1530
+ ,
1531
+ literal-value:
1532
+ show
1533
+ CURRENT_TIMESTAMP
1534
+ numeric-literal
1535
+ string-literal
1536
+ blob-literal
1537
+ NULL
1538
+ TRUE
1539
+ FALSE
1540
+ CURRENT_TIME
1541
+ CURRENT_DATE
1542
+ over-clause:
1543
+ show
1544
+ OVER
1545
+ window-name
1546
+ (
1547
+ base-window-name
1548
+ PARTITION
1549
+ BY
1550
+ expr
1551
+ ,
1552
+ ORDER
1553
+ BY
1554
+ ordering-term
1555
+ ,
1556
+ frame-spec
1557
+ )
1558
+ frame-spec:
1559
+ show
1560
+ GROUPS
1561
+ BETWEEN
1562
+ UNBOUNDED
1563
+ PRECEDING
1564
+ AND
1565
+ UNBOUNDED
1566
+ FOLLOWING
1567
+ RANGE
1568
+ ROWS
1569
+ UNBOUNDED
1570
+ PRECEDING
1571
+ expr
1572
+ PRECEDING
1573
+ CURRENT
1574
+ ROW
1575
+ expr
1576
+ PRECEDING
1577
+ CURRENT
1578
+ ROW
1579
+ expr
1580
+ FOLLOWING
1581
+ expr
1582
+ PRECEDING
1583
+ CURRENT
1584
+ ROW
1585
+ expr
1586
+ FOLLOWING
1587
+ EXCLUDE
1588
+ CURRENT
1589
+ ROW
1590
+ EXCLUDE
1591
+ GROUP
1592
+ EXCLUDE
1593
+ TIES
1594
+ EXCLUDE
1595
+ NO
1596
+ OTHERS
1597
+ raise-function:
1598
+ show
1599
+ RAISE
1600
+ (
1601
+ ROLLBACK
1602
+ ,
1603
+ expr
1604
+ )
1605
+ IGNORE
1606
+ ABORT
1607
+ FAIL
1608
+ select-stmt:
1609
+ show
1610
+ WITH
1611
+ RECURSIVE
1612
+ common-table-expression
1613
+ ,
1614
+ SELECT
1615
+ DISTINCT
1616
+ result-column
1617
+ ,
1618
+ ALL
1619
+ FROM
1620
+ table-or-subquery
1621
+ join-clause
1622
+ ,
1623
+ WHERE
1624
+ expr
1625
+ GROUP
1626
+ BY
1627
+ expr
1628
+ HAVING
1629
+ expr
1630
+ ,
1631
+ WINDOW
1632
+ window-name
1633
+ AS
1634
+ window-defn
1635
+ ,
1636
+ VALUES
1637
+ (
1638
+ expr
1639
+ )
1640
+ ,
1641
+ ,
1642
+ compound-operator
1643
+ select-core
1644
+ ORDER
1645
+ BY
1646
+ LIMIT
1647
+ expr
1648
+ ordering-term
1649
+ ,
1650
+ OFFSET
1651
+ expr
1652
+ ,
1653
+ expr
1654
+ compound-operator:
1655
+ show
1656
+ UNION
1657
+ UNION
1658
+ INTERSECT
1659
+ EXCEPT
1660
+ ALL
1661
+ join-clause:
1662
+ show
1663
+ table-or-subquery
1664
+ join-operator
1665
+ table-or-subquery
1666
+ join-constraint
1667
+ join-constraint:
1668
+ show
1669
+ USING
1670
+ (
1671
+ column-name
1672
+ )
1673
+ ,
1674
+ ON
1675
+ expr
1676
+ join-operator:
1677
+ show
1678
+ NATURAL
1679
+ LEFT
1680
+ OUTER
1681
+ JOIN
1682
+ ,
1683
+ RIGHT
1684
+ FULL
1685
+ INNER
1686
+ CROSS
1687
+ result-column:
1688
+ show
1689
+ expr
1690
+ AS
1691
+ column-alias
1692
+ *
1693
+ table-name
1694
+ .
1695
+ *
1696
+ table-or-subquery:
1697
+ show
1698
+ schema-name
1699
+ .
1700
+ table-name
1701
+ AS
1702
+ table-alias
1703
+ INDEXED
1704
+ BY
1705
+ index-name
1706
+ NOT
1707
+ INDEXED
1708
+ table-function-name
1709
+ (
1710
+ expr
1711
+ )
1712
+ ,
1713
+ AS
1714
+ table-alias
1715
+ (
1716
+ select-stmt
1717
+ )
1718
+ (
1719
+ table-or-subquery
1720
+ )
1721
+ ,
1722
+ join-clause
1723
+ window-defn:
1724
+ show
1725
+ (
1726
+ base-window-name
1727
+ PARTITION
1728
+ BY
1729
+ expr
1730
+ ,
1731
+ ORDER
1732
+ BY
1733
+ ordering-term
1734
+ ,
1735
+ frame-spec
1736
+ )
1737
+ frame-spec:
1738
+ show
1739
+ GROUPS
1740
+ BETWEEN
1741
+ UNBOUNDED
1742
+ PRECEDING
1743
+ AND
1744
+ UNBOUNDED
1745
+ FOLLOWING
1746
+ RANGE
1747
+ ROWS
1748
+ UNBOUNDED
1749
+ PRECEDING
1750
+ expr
1751
+ PRECEDING
1752
+ CURRENT
1753
+ ROW
1754
+ expr
1755
+ PRECEDING
1756
+ CURRENT
1757
+ ROW
1758
+ expr
1759
+ FOLLOWING
1760
+ expr
1761
+ PRECEDING
1762
+ CURRENT
1763
+ ROW
1764
+ expr
1765
+ FOLLOWING
1766
+ EXCLUDE
1767
+ CURRENT
1768
+ ROW
1769
+ EXCLUDE
1770
+ GROUP
1771
+ EXCLUDE
1772
+ TIES
1773
+ EXCLUDE
1774
+ NO
1775
+ OTHERS
1776
+ type-name:
1777
+ show
1778
+ name
1779
+ (
1780
+ signed-number
1781
+ ,
1782
+ signed-number
1783
+ )
1784
+ (
1785
+ signed-number
1786
+ )
1787
+ signed-number:
1788
+ show
1789
+ +
1790
+ numeric-literal
1791
+ -
1792
+ ordering-term:
1793
+ show
1794
+ expr
1795
+ COLLATE
1796
+ collation-name
1797
+ DESC
1798
+ ASC
1799
+ NULLS
1800
+ FIRST
1801
+ NULLS
1802
+ LAST
1803
+ select-core:
1804
+ hide
1805
+ SELECT
1806
+ DISTINCT
1807
+ result-column
1808
+ ,
1809
+ ALL
1810
+ FROM
1811
+ table-or-subquery
1812
+ join-clause
1813
+ ,
1814
+ WHERE
1815
+ expr
1816
+ GROUP
1817
+ BY
1818
+ expr
1819
+ HAVING
1820
+ expr
1821
+ ,
1822
+ WINDOW
1823
+ window-name
1824
+ AS
1825
+ window-defn
1826
+ ,
1827
+ VALUES
1828
+ (
1829
+ expr
1830
+ )
1831
+ ,
1832
+ ,
1833
+ join-clause:
1834
+ show
1835
+ table-or-subquery
1836
+ join-operator
1837
+ table-or-subquery
1838
+ join-constraint
1839
+ join-constraint:
1840
+ show
1841
+ USING
1842
+ (
1843
+ column-name
1844
+ )
1845
+ ,
1846
+ ON
1847
+ expr
1848
+ join-operator:
1849
+ show
1850
+ NATURAL
1851
+ LEFT
1852
+ OUTER
1853
+ JOIN
1854
+ ,
1855
+ RIGHT
1856
+ FULL
1857
+ INNER
1858
+ CROSS
1859
+ result-column:
1860
+ show
1861
+ expr
1862
+ AS
1863
+ column-alias
1864
+ *
1865
+ table-name
1866
+ .
1867
+ *
1868
+ table-or-subquery:
1869
+ show
1870
+ schema-name
1871
+ .
1872
+ table-name
1873
+ AS
1874
+ table-alias
1875
+ INDEXED
1876
+ BY
1877
+ index-name
1878
+ NOT
1879
+ INDEXED
1880
+ table-function-name
1881
+ (
1882
+ expr
1883
+ )
1884
+ ,
1885
+ AS
1886
+ table-alias
1887
+ (
1888
+ select-stmt
1889
+ )
1890
+ (
1891
+ table-or-subquery
1892
+ )
1893
+ ,
1894
+ join-clause
1895
+ select-stmt:
1896
+ show
1897
+ WITH
1898
+ RECURSIVE
1899
+ common-table-expression
1900
+ ,
1901
+ SELECT
1902
+ DISTINCT
1903
+ result-column
1904
+ ,
1905
+ ALL
1906
+ FROM
1907
+ table-or-subquery
1908
+ join-clause
1909
+ ,
1910
+ WHERE
1911
+ expr
1912
+ GROUP
1913
+ BY
1914
+ expr
1915
+ HAVING
1916
+ expr
1917
+ ,
1918
+ WINDOW
1919
+ window-name
1920
+ AS
1921
+ window-defn
1922
+ ,
1923
+ VALUES
1924
+ (
1925
+ expr
1926
+ )
1927
+ ,
1928
+ ,
1929
+ compound-operator
1930
+ select-core
1931
+ ORDER
1932
+ BY
1933
+ LIMIT
1934
+ expr
1935
+ ordering-term
1936
+ ,
1937
+ OFFSET
1938
+ expr
1939
+ ,
1940
+ expr
1941
+ compound-operator:
1942
+ show
1943
+ UNION
1944
+ UNION
1945
+ INTERSECT
1946
+ EXCEPT
1947
+ ALL
1948
+ window-defn:
1949
+ show
1950
+ (
1951
+ base-window-name
1952
+ PARTITION
1953
+ BY
1954
+ expr
1955
+ ,
1956
+ ORDER
1957
+ BY
1958
+ ordering-term
1959
+ ,
1960
+ frame-spec
1961
+ )
1962
+ frame-spec:
1963
+ show
1964
+ GROUPS
1965
+ BETWEEN
1966
+ UNBOUNDED
1967
+ PRECEDING
1968
+ AND
1969
+ UNBOUNDED
1970
+ FOLLOWING
1971
+ RANGE
1972
+ ROWS
1973
+ UNBOUNDED
1974
+ PRECEDING
1975
+ expr
1976
+ PRECEDING
1977
+ CURRENT
1978
+ ROW
1979
+ expr
1980
+ PRECEDING
1981
+ CURRENT
1982
+ ROW
1983
+ expr
1984
+ FOLLOWING
1985
+ expr
1986
+ PRECEDING
1987
+ CURRENT
1988
+ ROW
1989
+ expr
1990
+ FOLLOWING
1991
+ EXCLUDE
1992
+ CURRENT
1993
+ ROW
1994
+ EXCLUDE
1995
+ GROUP
1996
+ EXCLUDE
1997
+ TIES
1998
+ EXCLUDE
1999
+ NO
2000
+ OTHERS
2001
+ Generating the results of a simple SELECT
2002
+ statement is presented as a four step process in the description below:
2003
+ FROM clause processing: The input data for the simple SELECT is
2004
+ determined. The input data is either implicitly a single row with 0
2005
+ columns (if there is no FROM clause) or is determined by the FROM
2006
+ clause.
2007
+ WHERE clause processing: The input data is filtered using the WHERE
2008
+ clause expression.
2009
+ GROUP BY, HAVING and result-column expression processing:
2010
+ The set of result rows is computed by aggregating the data according to
2011
+ any GROUP BY clause and calculating the result-set expressions for the
2012
+ rows of the filtered input dataset.
2013
+ DISTINCT/ALL keyword processing: If the query is a "SELECT
2014
+ DISTINCT" query, duplicate rows are removed from the set of result rows.
2015
+ There are two types of simple SELECT statement - aggregate and
2016
+ non-aggregate queries. A simple SELECT statement is an aggregate query if
2017
+ it contains either a GROUP BY clause or one or more aggregate functions
2018
+ in the result-set. Otherwise, if a simple SELECT contains no aggregate
2019
+ functions or a GROUP BY clause, it is a non-aggregate query.
2020
+ 2.1. Determination of input data (FROM clause processing)
2021
+ The input data used by a simple SELECT query is a set of N rows
2022
+ each M columns wide.
2023
+ If the FROM clause is omitted from a simple SELECT statement, then the
2024
+ input data is implicitly a single row zero columns wide (i.e. N =1 and
2025
+ M =0).
2026
+ If a FROM clause is specified, the data on which a simple SELECT query
2027
+ operates comes from the one or more tables or subqueries (SELECT statements
2028
+ in parentheses) specified following the FROM keyword. A subquery specified
2029
+ in the table-or-subquery following the FROM clause in a
2030
+ simple SELECT statement is
2031
+ handled as if it was a table containing the data returned by executing the
2032
+ subquery statement. Each column of the subquery has the
2033
+ collation sequence and affinity of the corresponding expression
2034
+ in the subquery statement.
2035
+ If there is only a single table or subquery in the FROM
2036
+ clause, then the input data used by the SELECT statement is the contents of the
2037
+ named table. If there is more than one table or subquery in the FROM clause
2038
+ then the contents of all tables and/or subqueries
2039
+ are joined into a single dataset for the simple SELECT statement to operate on.
2040
+ Exactly how the data is combined depends on the specific join-operator and
2041
+ join-constraint used to connect the tables or subqueries together.
2042
+ All joins in SQLite are based on the cartesian product of the left and
2043
+ right-hand datasets. The columns of the cartesian product dataset are, in
2044
+ order, all the columns of the left-hand dataset followed by all the columns
2045
+ of the right-hand dataset. There is a row in the cartesian product dataset
2046
+ formed by combining each unique combination of a row from the left-hand
2047
+ and right-hand datasets. In other words, if the left-hand dataset consists of
2048
+ N left rows of
2049
+ M left columns, and the right-hand dataset of
2050
+ N right rows of
2051
+ M right columns, then the cartesian product is a
2052
+ dataset of
2053
+ N left ×N right
2054
+ rows, each containing
2055
+ M left +M right columns.
2056
+ If the join-operator is "CROSS JOIN", "INNER JOIN", "JOIN" or a comma
2057
+ (",") and there is no ON or USING clause, then the result of the join is
2058
+ simply the cartesian product of the left and right-hand datasets.
2059
+ If join-operator does have ON or USING clauses, those are handled according to
2060
+ the following bullet points:
2061
+ If there is an ON clause then the ON expression is
2062
+ evaluated for each row of the cartesian product as a
2063
+ boolean expression . Only rows for which the expression evaluates to
2064
+ true are included from the dataset.
2065
+ If there is a USING clause
2066
+ then each of the column names specified must exist in the datasets to
2067
+ both the left and right of the join-operator. For each pair of named
2068
+ columns, the expression "lhs.X = rhs.X" is evaluated for each row of
2069
+ the cartesian product as a boolean expression . Only rows for which
2070
+ all such expressions evaluate to true are included from the
2071
+ result set. When comparing values as a result of a USING clause, the
2072
+ normal rules for handling affinities, collation sequences and NULL
2073
+ values in comparisons apply. The column from the dataset on the
2074
+ left-hand side of the join-operator is considered to be on the left-hand
2075
+ side of the comparison operator (=) for the purposes of collation
2076
+ sequence and affinity precedence.
2077
+ For each pair of columns identified by a USING clause, the column
2078
+ from the right-hand dataset is omitted from the joined dataset. This
2079
+ is the only difference between a USING clause and its equivalent ON
2080
+ constraint.
2081
+ If the NATURAL keyword is in the join-operator then an
2082
+ implicit USING clause is added to the join-constraints. The implicit
2083
+ USING clause contains each of the column names that appear in both
2084
+ the left and right-hand input datasets. If the left and right-hand
2085
+ input datasets feature no common column names, then the NATURAL keyword
2086
+ has no effect on the results of the join. A USING or ON clause may
2087
+ not be added to a join that specifies the NATURAL keyword.
2088
+ If the join-operator is a "LEFT JOIN" or "LEFT OUTER JOIN", then
2089
+ after
2090
+ the ON or USING filtering clauses have been applied, an extra row is
2091
+ added to the output for each row in the original left-hand input
2092
+ dataset that does not match any row in the right-hand dataset.
2093
+ The added rows contain NULL values in the columns
2094
+ that would normally contain values copied from the right-hand input
2095
+ dataset.
2096
+ If the join-operator is a "RIGHT JOIN" or "RIGHT OUTER JOIN", then
2097
+ after the ON or USING filtering clauses have been applied, an extra row is
2098
+ added to the output for each row in the original right-hand input
2099
+ dataset that does not match any row in the left-hand dataset.
2100
+ The added rows contain NULL values in the columns
2101
+ that would normally contain values copied from the left-hand input
2102
+ dataset.
2103
+ A "FULL JOIN" or "FULL OUTER JOIN" is a combination of a
2104
+ "LEFT JOIN" and a "RIGHT JOIN". Extra rows of output are
2105
+ added for each row in left dataset that matches no rows in the right,
2106
+ and for each row in the right dataset that matches no rows in the
2107
+ left. Unmatched columns are filled in with NULL.
2108
+ When more than two tables are joined together as part of a FROM clause,
2109
+ the join operations are processed in order from left to right. In other
2110
+ words, the FROM clause (A join-op-1 B join-op-2 C) is computed as
2111
+ ((A join-op-1 B) join-op-2 C).
2112
+ 2.2. Special handling of CROSS JOIN.
2113
+ There is no difference between the "INNER JOIN", "JOIN" and "," join
2114
+ operators. They are completely interchangeable in SQLite.
2115
+ The "CROSS JOIN" join operator produces the same result as the
2116
+ "INNER JOIN", "JOIN" and "," operators, but is
2117
+ handled differently by the query optimizer
2118
+ in that it prevents the query optimizer from reordering
2119
+ the tables in the join. An application programmer can use the CROSS JOIN
2120
+ operator to directly influence the algorithm that is chosen to implement
2121
+ the SELECT statement. Avoid using CROSS JOIN except in specific situations
2122
+ where manual control of the query optimizer is desired. Avoid using
2123
+ CROSS JOIN early in the development of an application as doing so is
2124
+ a premature
2125
+ optimization . The special handling of CROSS JOIN is an SQLite-specific
2126
+ feature and is not a part of standard SQL.
2127
+ 2.3. WHERE clause filtering.
2128
+ If a WHERE clause is specified, the WHERE expression is evaluated for
2129
+ each row in the input data as a boolean expression . Only rows for which the
2130
+ WHERE clause expression evaluates to true are included from the dataset before
2131
+ continuing. Rows are excluded from the result if the WHERE clause
2132
+ evaluates to either false or NULL.
2133
+ For a JOIN or INNER JOIN or CROSS JOIN, there is no difference between
2134
+ a constraint expression in the WHERE clause and one in the ON clause. However,
2135
+ for a LEFT or RIGHT or FULL OUTER JOIN, the difference is very important.
2136
+ In an outer join, the extra NULL rows for non-matched rows on the other
2137
+ operand are added after ON clause processing
2138
+ but before WHERE clause processing. A constraint of the form "left.x=right.y"
2139
+ in an ON clause will therefore allow through for the added all-NULL rows.
2140
+ But if that same constraint is in the WHERE clause, a NULL in one of
2141
+ "right.y" or "left.x" will prevent the expression "left.x=right.y" from being true,
2142
+ and thus exclude that row from the output.
2143
+ 2.4. Generation of the set of result rows
2144
+ Once the input data from the FROM clause has been filtered by the
2145
+ WHERE clause expression (if any), the set of result rows for the simple
2146
+ SELECT are calculated. Exactly how this is done depends on whether the simple
2147
+ SELECT is an aggregate or non-aggregate query, and whether or not a GROUP
2148
+ BY clause was specified.
2149
+ The list of expressions between the SELECT and FROM keywords is known as
2150
+ the result expression list. If a result expression is the special expression
2151
+ "*" then all columns in the input data are substituted for that one expression.
2152
+ If the expression is the alias of a table or subquery in the FROM clause
2153
+ followed by ".*" then all columns from the named table or subquery are
2154
+ substituted for the single expression. It is an error to use a "*" or
2155
+ "alias.*" expression in any context other than a result expression list.
2156
+ It is also an error to use a "*" or "alias.*" expression in a simple SELECT
2157
+ query that does not have a FROM clause.
2158
+ The number of columns in the rows returned by a simple SELECT statement
2159
+ is equal to the number of expressions in the result expression list after
2160
+ substitution of * and alias.* expressions. Each result row is calculated by
2161
+ evaluating the expressions in the result expression list with respect to a
2162
+ single row of input data or, for aggregate queries, with respect to a group
2163
+ of rows.
2164
+ If the SELECT statement is a non-aggregate query , then
2165
+ each expression in the result expression list is evaluated for each row in
2166
+ the dataset filtered by the WHERE clause.
2167
+ If the SELECT statement is an aggregate query without a GROUP
2168
+ BY clause, then each aggregate expression in the result-set is
2169
+ evaluated once across the entire dataset. Each non-aggregate expression
2170
+ in the result-set is evaluated once for an arbitrarily selected row of
2171
+ the dataset. The same arbitrarily selected row is used for each
2172
+ non-aggregate expression. Or, if the dataset contains zero rows, then
2173
+ each non-aggregate expression is evaluated against a row consisting
2174
+ entirely of NULL values.
2175
+ The single row of result-set data created by evaluating the aggregate
2176
+ and non-aggregate expressions in the result-set forms the result of an
2177
+ aggregate query without a GROUP BY clause. An aggregate query without a
2178
+ GROUP BY clause always returns exactly one row of data, even if there are
2179
+ zero rows of input data.
2180
+ If the SELECT statement is an aggregate query with a GROUP
2181
+ BY clause, then each of the expressions specified as part of the
2182
+ GROUP BY clause is evaluated for each row of the dataset according to
2183
+ the processing rules stated below for ORDER BY expressions. Each row
2184
+ is then assigned to a "group" based on the results; rows for which
2185
+ the results of evaluating the GROUP BY expressions are the same get
2186
+ assigned to the same group. For the purposes of grouping rows, NULL
2187
+ values are considered equal. The usual rules for selecting a
2188
+ collation sequence with which to compare text values apply when evaluating
2189
+ expressions in a GROUP BY clause. The expressions in the GROUP BY clause
2190
+ do not have to be expressions that appear in the result. The
2191
+ expressions in a GROUP BY clause may not be aggregate expressions.
2192
+ If a HAVING clause is specified, it is evaluated once for each group
2193
+ of rows as a boolean expression . If the result of evaluating the
2194
+ HAVING clause is false, the group is discarded. If the HAVING clause is
2195
+ an aggregate expression, it is evaluated across all rows in the group. If
2196
+ a HAVING clause is a non-aggregate expression, it is evaluated with respect
2197
+ to an arbitrarily selected row from the group. The HAVING expression may
2198
+ refer to values, even aggregate functions, that are not in the result.
2199
+ Each expression in the result-set is then evaluated once for each
2200
+ group of rows. If the expression is an aggregate expression, it is
2201
+ evaluated across all rows in the group. Otherwise, it is evaluated against
2202
+ a single arbitrarily chosen row from within the group. If there is more
2203
+ than one non-aggregate expression in the result-set, then all such
2204
+ expressions are evaluated for the same row.
2205
+ Each group of input dataset rows contributes a single row to the
2206
+ set of result rows. Subject to filtering associated with the DISTINCT
2207
+ keyword, the number of rows returned by an aggregate query with a GROUP
2208
+ BY clause is the same as the number of groups of rows produced by applying
2209
+ the GROUP BY and HAVING clauses to the filtered input dataset.
2210
+ 2.5. Bare columns in an aggregate query
2211
+ The usual case is that all column names in an aggregate query are either
2212
+ arguments to aggregate functions or else appear in the GROUP BY clause.
2213
+ A result column which contains a column name that is not within an
2214
+ aggregate function and that does not appear in the GROUP BY clause (if
2215
+ one exists) is called a "bare" column.
2216
+ Example:
2217
+ In the query above, the "a" column is part of the GROUP BY clause
2218
+ and so each row of the output contains one of the distinct values for
2219
+ "a". The "c" column is contained within the sum() aggregate function
2220
+ and so that output column is the sum of all "c" values in rows that
2221
+ have the same value for "a". But what is the result of the bare
2222
+ column "b"? The answer is that the "b" result will be the
2223
+ value for "b" in one of the input rows that form the aggregate.¹
2224
+ The problem is that you usually do not know which input row is used
2225
+ to compute "b", and so in many cases the value for "b" is undefined.
2226
+ Special processing occurs when the aggregate function is
2227
+ either min() or max() . Example:
2228
+ If there is exactly one min() or max() aggregate
2229
+ in the query, then all bare columns in the result set take values from an
2230
+ input row which also contains the minimum or maximum. So in the query
2231
+ above, the value of the "b" column in the output will be the value of
2232
+ the "b" column in the input row that has the largest "c" value.
2233
+ There are limitations on this special behavior of
2234
+ min() and max() :
2235
+ If the same minimum or maximum value occurs on two or more rows,
2236
+ then bare values might be selected from any of those rows. The choice
2237
+ is arbitrary. There is no way to predict from which row the bare values
2238
+ will be choosen. The choice might be different for different bare columns
2239
+ within the same query.
2240
+ If there are two or more min() or max() aggregates
2241
+ in the query, then bare column values will be taken from one of the rows
2242
+ on which one of the aggregates has their minimum or maximum value. The choice
2243
+ of which min() or max() aggregate determines the
2244
+ selection of bare column values is arbitrary. The choice might be different
2245
+ for different bare columns within the same query.
2246
+ This special processing for min() or max() aggregates
2247
+ only works for the built-in implementation of those aggregates. If an
2248
+ application overrides the built-in min() or max() aggregates
2249
+ with application-defined alternatives, then the values selected for bare
2250
+ columns will be taken from an arbitrary row.
2251
+ Most other SQL database engines disallow bare columns. If you include
2252
+ a bare column in a query, other database engines will usually raise an error.
2253
+ The ability to include bare columns in a query is an SQLite-specific extension.
2254
+ This is considered a feature, not a bug. See the discussion on
2255
+ SQLite Forum thread 7481d2a6df8980ff
2256
+ for additional information.
2257
+ 2.5.1. Notes
2258
+ If the aggregate is composed from one or more input rows, then a bare column
2259
+ will take on the value of an arbitrary row from the aggregate's input.
2260
+ The particular row chosen might change from one invocation to the
2261
+ the next. If the aggregate is empty (if the aggregate has no input rows,
2262
+ as happens if no rows match the WHERE clause), then the bare column can
2263
+ take on any arbitrary value, including values that are not found anywhere
2264
+ in the tables of the FROM clause.
2265
+ 2.6. Removal of duplicate rows (DISTINCT processing)
2266
+ One of the ALL or DISTINCT keywords may follow the SELECT keyword in a
2267
+ simple SELECT statement. If the simple SELECT is a SELECT ALL, then the
2268
+ entire set of result rows are returned by the SELECT. If neither ALL or
2269
+ DISTINCT are present, then the behavior is as if ALL were specified.
2270
+ If the simple SELECT is a SELECT DISTINCT, then duplicate rows are removed
2271
+ from the set of result rows before it is returned. For the purposes of
2272
+ detecting duplicate rows, values are compared using the IS DISTINCT FROM operator.
2273
+ Thus two NULL values are considered to be equal. An integer is equal
2274
+ to a floating point number if they represent the same quantity.
2275
+ Text values are compared using an appropriate collation sequence.
2276
+ The usual rules apply for selecting a collation
2277
+ sequence to compare text values.
2278
+ BLOB affinity is used for DISTINCT comparisons, hence no type
2279
+ coercions occur.
2280
+ 3. Compound Select Statements
2281
+ Two or more simple SELECT statements may be connected together to form
2282
+ a compound SELECT using the UNION, UNION ALL, INTERSECT or EXCEPT operator,
2283
+ as shown by the following diagram:
2284
+ compound-select-stmt:
2285
+ hide
2286
+ WITH
2287
+ RECURSIVE
2288
+ common-table-expression
2289
+ ,
2290
+ select-core
2291
+ ORDER
2292
+ BY
2293
+ LIMIT
2294
+ expr
2295
+ UNION
2296
+ UNION
2297
+ ALL
2298
+ select-core
2299
+ INTERSECT
2300
+ EXCEPT
2301
+ ordering-term
2302
+ ,
2303
+ OFFSET
2304
+ expr
2305
+ ,
2306
+ expr
2307
+ common-table-expression:
2308
+ show
2309
+ table-name
2310
+ (
2311
+ column-name
2312
+ )
2313
+ AS
2314
+ NOT
2315
+ MATERIALIZED
2316
+ (
2317
+ select-stmt
2318
+ )
2319
+ ,
2320
+ select-stmt:
2321
+ show
2322
+ WITH
2323
+ RECURSIVE
2324
+ common-table-expression
2325
+ ,
2326
+ SELECT
2327
+ DISTINCT
2328
+ result-column
2329
+ ,
2330
+ ALL
2331
+ FROM
2332
+ table-or-subquery
2333
+ join-clause
2334
+ ,
2335
+ WHERE
2336
+ expr
2337
+ GROUP
2338
+ BY
2339
+ expr
2340
+ HAVING
2341
+ expr
2342
+ ,
2343
+ WINDOW
2344
+ window-name
2345
+ AS
2346
+ window-defn
2347
+ ,
2348
+ VALUES
2349
+ (
2350
+ expr
2351
+ )
2352
+ ,
2353
+ ,
2354
+ compound-operator
2355
+ select-core
2356
+ ORDER
2357
+ BY
2358
+ LIMIT
2359
+ expr
2360
+ ordering-term
2361
+ ,
2362
+ OFFSET
2363
+ expr
2364
+ ,
2365
+ expr
2366
+ compound-operator:
2367
+ show
2368
+ UNION
2369
+ UNION
2370
+ INTERSECT
2371
+ EXCEPT
2372
+ ALL
2373
+ join-clause:
2374
+ show
2375
+ table-or-subquery
2376
+ join-operator
2377
+ table-or-subquery
2378
+ join-constraint
2379
+ join-constraint:
2380
+ show
2381
+ USING
2382
+ (
2383
+ column-name
2384
+ )
2385
+ ,
2386
+ ON
2387
+ expr
2388
+ join-operator:
2389
+ show
2390
+ NATURAL
2391
+ LEFT
2392
+ OUTER
2393
+ JOIN
2394
+ ,
2395
+ RIGHT
2396
+ FULL
2397
+ INNER
2398
+ CROSS
2399
+ result-column:
2400
+ show
2401
+ expr
2402
+ AS
2403
+ column-alias
2404
+ *
2405
+ table-name
2406
+ .
2407
+ *
2408
+ table-or-subquery:
2409
+ show
2410
+ schema-name
2411
+ .
2412
+ table-name
2413
+ AS
2414
+ table-alias
2415
+ INDEXED
2416
+ BY
2417
+ index-name
2418
+ NOT
2419
+ INDEXED
2420
+ table-function-name
2421
+ (
2422
+ expr
2423
+ )
2424
+ ,
2425
+ AS
2426
+ table-alias
2427
+ (
2428
+ select-stmt
2429
+ )
2430
+ (
2431
+ table-or-subquery
2432
+ )
2433
+ ,
2434
+ join-clause
2435
+ window-defn:
2436
+ show
2437
+ (
2438
+ base-window-name
2439
+ PARTITION
2440
+ BY
2441
+ expr
2442
+ ,
2443
+ ORDER
2444
+ BY
2445
+ ordering-term
2446
+ ,
2447
+ frame-spec
2448
+ )
2449
+ frame-spec:
2450
+ show
2451
+ GROUPS
2452
+ BETWEEN
2453
+ UNBOUNDED
2454
+ PRECEDING
2455
+ AND
2456
+ UNBOUNDED
2457
+ FOLLOWING
2458
+ RANGE
2459
+ ROWS
2460
+ UNBOUNDED
2461
+ PRECEDING
2462
+ expr
2463
+ PRECEDING
2464
+ CURRENT
2465
+ ROW
2466
+ expr
2467
+ PRECEDING
2468
+ CURRENT
2469
+ ROW
2470
+ expr
2471
+ FOLLOWING
2472
+ expr
2473
+ PRECEDING
2474
+ CURRENT
2475
+ ROW
2476
+ expr
2477
+ FOLLOWING
2478
+ EXCLUDE
2479
+ CURRENT
2480
+ ROW
2481
+ EXCLUDE
2482
+ GROUP
2483
+ EXCLUDE
2484
+ TIES
2485
+ EXCLUDE
2486
+ NO
2487
+ OTHERS
2488
+ expr:
2489
+ show
2490
+ literal-value
2491
+ bind-parameter
2492
+ schema-name
2493
+ .
2494
+ table-name
2495
+ .
2496
+ column-name
2497
+ unary-operator
2498
+ expr
2499
+ expr
2500
+ binary-operator
2501
+ expr
2502
+ function-name
2503
+ (
2504
+ function-arguments
2505
+ )
2506
+ filter-clause
2507
+ over-clause
2508
+ (
2509
+ expr
2510
+ )
2511
+ ,
2512
+ CAST
2513
+ (
2514
+ expr
2515
+ AS
2516
+ type-name
2517
+ )
2518
+ expr
2519
+ COLLATE
2520
+ collation-name
2521
+ expr
2522
+ NOT
2523
+ LIKE
2524
+ GLOB
2525
+ REGEXP
2526
+ MATCH
2527
+ expr
2528
+ expr
2529
+ ESCAPE
2530
+ expr
2531
+ expr
2532
+ ISNULL
2533
+ NOTNULL
2534
+ NOT
2535
+ NULL
2536
+ expr
2537
+ IS
2538
+ NOT
2539
+ DISTINCT
2540
+ FROM
2541
+ expr
2542
+ expr
2543
+ NOT
2544
+ BETWEEN
2545
+ expr
2546
+ AND
2547
+ expr
2548
+ expr
2549
+ NOT
2550
+ IN
2551
+ (
2552
+ select-stmt
2553
+ )
2554
+ expr
2555
+ ,
2556
+ schema-name
2557
+ .
2558
+ table-function
2559
+ (
2560
+ expr
2561
+ )
2562
+ table-name
2563
+ ,
2564
+ NOT
2565
+ EXISTS
2566
+ (
2567
+ select-stmt
2568
+ )
2569
+ CASE
2570
+ expr
2571
+ WHEN
2572
+ expr
2573
+ THEN
2574
+ expr
2575
+ ELSE
2576
+ expr
2577
+ END
2578
+ raise-function
2579
+ filter-clause:
2580
+ show
2581
+ FILTER
2582
+ (
2583
+ WHERE
2584
+ expr
2585
+ )
2586
+ function-arguments:
2587
+ show
2588
+ DISTINCT
2589
+ expr
2590
+ ,
2591
+ *
2592
+ ORDER
2593
+ BY
2594
+ ordering-term
2595
+ ,
2596
+ literal-value:
2597
+ show
2598
+ CURRENT_TIMESTAMP
2599
+ numeric-literal
2600
+ string-literal
2601
+ blob-literal
2602
+ NULL
2603
+ TRUE
2604
+ FALSE
2605
+ CURRENT_TIME
2606
+ CURRENT_DATE
2607
+ over-clause:
2608
+ show
2609
+ OVER
2610
+ window-name
2611
+ (
2612
+ base-window-name
2613
+ PARTITION
2614
+ BY
2615
+ expr
2616
+ ,
2617
+ ORDER
2618
+ BY
2619
+ ordering-term
2620
+ ,
2621
+ frame-spec
2622
+ )
2623
+ frame-spec:
2624
+ show
2625
+ GROUPS
2626
+ BETWEEN
2627
+ UNBOUNDED
2628
+ PRECEDING
2629
+ AND
2630
+ UNBOUNDED
2631
+ FOLLOWING
2632
+ RANGE
2633
+ ROWS
2634
+ UNBOUNDED
2635
+ PRECEDING
2636
+ expr
2637
+ PRECEDING
2638
+ CURRENT
2639
+ ROW
2640
+ expr
2641
+ PRECEDING
2642
+ CURRENT
2643
+ ROW
2644
+ expr
2645
+ FOLLOWING
2646
+ expr
2647
+ PRECEDING
2648
+ CURRENT
2649
+ ROW
2650
+ expr
2651
+ FOLLOWING
2652
+ EXCLUDE
2653
+ CURRENT
2654
+ ROW
2655
+ EXCLUDE
2656
+ GROUP
2657
+ EXCLUDE
2658
+ TIES
2659
+ EXCLUDE
2660
+ NO
2661
+ OTHERS
2662
+ raise-function:
2663
+ show
2664
+ RAISE
2665
+ (
2666
+ ROLLBACK
2667
+ ,
2668
+ expr
2669
+ )
2670
+ IGNORE
2671
+ ABORT
2672
+ FAIL
2673
+ select-stmt:
2674
+ show
2675
+ WITH
2676
+ RECURSIVE
2677
+ common-table-expression
2678
+ ,
2679
+ SELECT
2680
+ DISTINCT
2681
+ result-column
2682
+ ,
2683
+ ALL
2684
+ FROM
2685
+ table-or-subquery
2686
+ join-clause
2687
+ ,
2688
+ WHERE
2689
+ expr
2690
+ GROUP
2691
+ BY
2692
+ expr
2693
+ HAVING
2694
+ expr
2695
+ ,
2696
+ WINDOW
2697
+ window-name
2698
+ AS
2699
+ window-defn
2700
+ ,
2701
+ VALUES
2702
+ (
2703
+ expr
2704
+ )
2705
+ ,
2706
+ ,
2707
+ compound-operator
2708
+ select-core
2709
+ ORDER
2710
+ BY
2711
+ LIMIT
2712
+ expr
2713
+ ordering-term
2714
+ ,
2715
+ OFFSET
2716
+ expr
2717
+ ,
2718
+ expr
2719
+ compound-operator:
2720
+ show
2721
+ UNION
2722
+ UNION
2723
+ INTERSECT
2724
+ EXCEPT
2725
+ ALL
2726
+ join-clause:
2727
+ show
2728
+ table-or-subquery
2729
+ join-operator
2730
+ table-or-subquery
2731
+ join-constraint
2732
+ join-constraint:
2733
+ show
2734
+ USING
2735
+ (
2736
+ column-name
2737
+ )
2738
+ ,
2739
+ ON
2740
+ expr
2741
+ join-operator:
2742
+ show
2743
+ NATURAL
2744
+ LEFT
2745
+ OUTER
2746
+ JOIN
2747
+ ,
2748
+ RIGHT
2749
+ FULL
2750
+ INNER
2751
+ CROSS
2752
+ result-column:
2753
+ show
2754
+ expr
2755
+ AS
2756
+ column-alias
2757
+ *
2758
+ table-name
2759
+ .
2760
+ *
2761
+ table-or-subquery:
2762
+ show
2763
+ schema-name
2764
+ .
2765
+ table-name
2766
+ AS
2767
+ table-alias
2768
+ INDEXED
2769
+ BY
2770
+ index-name
2771
+ NOT
2772
+ INDEXED
2773
+ table-function-name
2774
+ (
2775
+ expr
2776
+ )
2777
+ ,
2778
+ AS
2779
+ table-alias
2780
+ (
2781
+ select-stmt
2782
+ )
2783
+ (
2784
+ table-or-subquery
2785
+ )
2786
+ ,
2787
+ join-clause
2788
+ window-defn:
2789
+ show
2790
+ (
2791
+ base-window-name
2792
+ PARTITION
2793
+ BY
2794
+ expr
2795
+ ,
2796
+ ORDER
2797
+ BY
2798
+ ordering-term
2799
+ ,
2800
+ frame-spec
2801
+ )
2802
+ frame-spec:
2803
+ show
2804
+ GROUPS
2805
+ BETWEEN
2806
+ UNBOUNDED
2807
+ PRECEDING
2808
+ AND
2809
+ UNBOUNDED
2810
+ FOLLOWING
2811
+ RANGE
2812
+ ROWS
2813
+ UNBOUNDED
2814
+ PRECEDING
2815
+ expr
2816
+ PRECEDING
2817
+ CURRENT
2818
+ ROW
2819
+ expr
2820
+ PRECEDING
2821
+ CURRENT
2822
+ ROW
2823
+ expr
2824
+ FOLLOWING
2825
+ expr
2826
+ PRECEDING
2827
+ CURRENT
2828
+ ROW
2829
+ expr
2830
+ FOLLOWING
2831
+ EXCLUDE
2832
+ CURRENT
2833
+ ROW
2834
+ EXCLUDE
2835
+ GROUP
2836
+ EXCLUDE
2837
+ TIES
2838
+ EXCLUDE
2839
+ NO
2840
+ OTHERS
2841
+ type-name:
2842
+ show
2843
+ name
2844
+ (
2845
+ signed-number
2846
+ ,
2847
+ signed-number
2848
+ )
2849
+ (
2850
+ signed-number
2851
+ )
2852
+ signed-number:
2853
+ show
2854
+ +
2855
+ numeric-literal
2856
+ -
2857
+ ordering-term:
2858
+ show
2859
+ expr
2860
+ COLLATE
2861
+ collation-name
2862
+ DESC
2863
+ ASC
2864
+ NULLS
2865
+ FIRST
2866
+ NULLS
2867
+ LAST
2868
+ select-core:
2869
+ show
2870
+ SELECT
2871
+ DISTINCT
2872
+ result-column
2873
+ ,
2874
+ ALL
2875
+ FROM
2876
+ table-or-subquery
2877
+ join-clause
2878
+ ,
2879
+ WHERE
2880
+ expr
2881
+ GROUP
2882
+ BY
2883
+ expr
2884
+ HAVING
2885
+ expr
2886
+ ,
2887
+ WINDOW
2888
+ window-name
2889
+ AS
2890
+ window-defn
2891
+ ,
2892
+ VALUES
2893
+ (
2894
+ expr
2895
+ )
2896
+ ,
2897
+ ,
2898
+ join-clause:
2899
+ show
2900
+ table-or-subquery
2901
+ join-operator
2902
+ table-or-subquery
2903
+ join-constraint
2904
+ join-constraint:
2905
+ show
2906
+ USING
2907
+ (
2908
+ column-name
2909
+ )
2910
+ ,
2911
+ ON
2912
+ expr
2913
+ join-operator:
2914
+ show
2915
+ NATURAL
2916
+ LEFT
2917
+ OUTER
2918
+ JOIN
2919
+ ,
2920
+ RIGHT
2921
+ FULL
2922
+ INNER
2923
+ CROSS
2924
+ result-column:
2925
+ show
2926
+ expr
2927
+ AS
2928
+ column-alias
2929
+ *
2930
+ table-name
2931
+ .
2932
+ *
2933
+ table-or-subquery:
2934
+ show
2935
+ schema-name
2936
+ .
2937
+ table-name
2938
+ AS
2939
+ table-alias
2940
+ INDEXED
2941
+ BY
2942
+ index-name
2943
+ NOT
2944
+ INDEXED
2945
+ table-function-name
2946
+ (
2947
+ expr
2948
+ )
2949
+ ,
2950
+ AS
2951
+ table-alias
2952
+ (
2953
+ select-stmt
2954
+ )
2955
+ (
2956
+ table-or-subquery
2957
+ )
2958
+ ,
2959
+ join-clause
2960
+ select-stmt:
2961
+ show
2962
+ WITH
2963
+ RECURSIVE
2964
+ common-table-expression
2965
+ ,
2966
+ SELECT
2967
+ DISTINCT
2968
+ result-column
2969
+ ,
2970
+ ALL
2971
+ FROM
2972
+ table-or-subquery
2973
+ join-clause
2974
+ ,
2975
+ WHERE
2976
+ expr
2977
+ GROUP
2978
+ BY
2979
+ expr
2980
+ HAVING
2981
+ expr
2982
+ ,
2983
+ WINDOW
2984
+ window-name
2985
+ AS
2986
+ window-defn
2987
+ ,
2988
+ VALUES
2989
+ (
2990
+ expr
2991
+ )
2992
+ ,
2993
+ ,
2994
+ compound-operator
2995
+ select-core
2996
+ ORDER
2997
+ BY
2998
+ LIMIT
2999
+ expr
3000
+ ordering-term
3001
+ ,
3002
+ OFFSET
3003
+ expr
3004
+ ,
3005
+ expr
3006
+ compound-operator:
3007
+ show
3008
+ UNION
3009
+ UNION
3010
+ INTERSECT
3011
+ EXCEPT
3012
+ ALL
3013
+ window-defn:
3014
+ show
3015
+ (
3016
+ base-window-name
3017
+ PARTITION
3018
+ BY
3019
+ expr
3020
+ ,
3021
+ ORDER
3022
+ BY
3023
+ ordering-term
3024
+ ,
3025
+ frame-spec
3026
+ )
3027
+ frame-spec:
3028
+ show
3029
+ GROUPS
3030
+ BETWEEN
3031
+ UNBOUNDED
3032
+ PRECEDING
3033
+ AND
3034
+ UNBOUNDED
3035
+ FOLLOWING
3036
+ RANGE
3037
+ ROWS
3038
+ UNBOUNDED
3039
+ PRECEDING
3040
+ expr
3041
+ PRECEDING
3042
+ CURRENT
3043
+ ROW
3044
+ expr
3045
+ PRECEDING
3046
+ CURRENT
3047
+ ROW
3048
+ expr
3049
+ FOLLOWING
3050
+ expr
3051
+ PRECEDING
3052
+ CURRENT
3053
+ ROW
3054
+ expr
3055
+ FOLLOWING
3056
+ EXCLUDE
3057
+ CURRENT
3058
+ ROW
3059
+ EXCLUDE
3060
+ GROUP
3061
+ EXCLUDE
3062
+ TIES
3063
+ EXCLUDE
3064
+ NO
3065
+ OTHERS
3066
+ In a compound SELECT, all the constituent SELECTs must return the same
3067
+ number of result columns. As the components of a compound SELECT must
3068
+ be simple SELECT statements, they may not contain ORDER BY or LIMIT clauses.
3069
+ ORDER BY and LIMIT clauses may only occur at the end of the entire compound
3070
+ SELECT, and then only if the final element of the compound is not a VALUES clause.
3071
+ A compound SELECT created using the UNION ALL operator returns all the rows
3072
+ from the SELECT to the left of the UNION ALL operator, and all the rows
3073
+ from the SELECT to the right of it. The UNION operator works the same way as
3074
+ UNION ALL, except that duplicate rows are removed from the final result set.
3075
+ The INTERSECT operator returns the intersection of the results of the left and
3076
+ right SELECTs. The EXCEPT operator returns the subset of rows returned by the
3077
+ left SELECT that are not also returned by the right-hand SELECT. Duplicate
3078
+ rows are removed from the results of INTERSECT and EXCEPT operators before the
3079
+ result set is returned.
3080
+ For the purposes of determining duplicate rows for the results of compound
3081
+ SELECT operators, NULL values are considered equal to other NULL values and
3082
+ distinct from all non-NULL values. The collation sequence used to compare
3083
+ two text values is determined as if the columns of the left and right-hand
3084
+ SELECT statements were the left and right-hand operands of the equals (=)
3085
+ operator, except that greater precedence is not assigned to a collation
3086
+ sequence specified with the postfix COLLATE operator. No affinity
3087
+ transformations are applied to any values when comparing rows as part of a
3088
+ compound SELECT.
3089
+ When three or more simple SELECTs are connected into a compound SELECT,
3090
+ they group from left to right. In other words, if "A", "B" and "C" are all
3091
+ simple SELECT statements, (A op B op C) is processed as ((A op B) op C).
3092
+ 4. The ORDER BY clause
3093
+ If a SELECT statement that returns more than one row does not have an
3094
+ ORDER BY clause, the order in which the rows are returned is undefined.
3095
+ Or, if a SELECT statement does have an ORDER BY clause, then the list of
3096
+ expressions attached to the ORDER BY determine the order in which rows
3097
+ are returned to the user.
3098
+ In a compound SELECT statement, only the last or right-most simple SELECT
3099
+ may have an ORDER BY clause. That ORDER BY clause will apply across all elements of
3100
+ the compound. If the right-most element of a compound SELECT is a VALUES clause,
3101
+ then no ORDER BY clause is allowed on that statement.
3102
+ Rows are first sorted based on the results of
3103
+ evaluating the left-most expression in the ORDER BY list, then ties are broken
3104
+ by evaluating the second left-most expression and so on. The order in which
3105
+ two rows for which all ORDER BY expressions evaluate to equal values are
3106
+ returned is undefined. Each ORDER BY expression may be optionally followed
3107
+ by one of the keywords ASC (smaller values are returned first) or DESC (larger
3108
+ values are returned first). If neither ASC or DESC are specified, rows
3109
+ are sorted in ascending (smaller values first) order by default.
3110
+ SQLite considers NULL values to be smaller than any other values
3111
+ for sorting purposes. Hence, NULLs naturally appear at the beginning
3112
+ of an ASC order-by and at the end of a DESC order-by. This can be changed
3113
+ using the "ASC NULLS LAST" or "DESC NULLS FIRST" syntax.
3114
+ Each ORDER BY expression is processed as follows:
3115
+ If the ORDER BY expression is a constant integer K then the
3116
+ expression is considered an alias for the K-th column of the result set
3117
+ (columns are numbered from left to right starting with 1).
3118
+ If the ORDER BY expression is an identifier that corresponds to
3119
+ the alias of one of the output columns, then the expression is considered
3120
+ an alias for that column.
3121
+ Otherwise, if the ORDER BY expression is any other expression, it
3122
+ is evaluated and the returned value used to order the output rows. If
3123
+ the SELECT statement is a simple SELECT, then an ORDER BY may contain any
3124
+ arbitrary expressions. However, if the SELECT is a compound SELECT, then
3125
+ ORDER BY expressions that are not aliases to output columns must be exactly
3126
+ the same as an expression used as an output column.
3127
+ For the purposes of sorting rows, values are compared in the same way
3128
+ as for comparison expressions . The collation sequence used to compare
3129
+ two text values is determined as follows:
3130
+ If the ORDER BY expression is assigned a collation sequence using
3131
+ the postfix COLLATE operator , then the specified collation sequence is
3132
+ used.
3133
+ Otherwise, if the ORDER BY expression is an alias to an expression
3134
+ that has been assigned a collation sequence using the postfix
3135
+ COLLATE operator , then the collation sequence assigned to the aliased
3136
+ expression is used.
3137
+ Otherwise, if the ORDER BY expression is a column or an alias of
3138
+ an expression that is a column, then the default collation sequence for
3139
+ the column is used.
3140
+ Otherwise, the BINARY collation sequence is used.
3141
+ In a compound SELECT statement, all ORDER BY expressions are handled
3142
+ as aliases for one of the result columns of the compound.
3143
+ If an ORDER BY expression is not an integer alias, then SQLite searches
3144
+ the left-most SELECT in the compound for a result column that matches either
3145
+ the second or third rules above. If a match is found, the search stops and
3146
+ the expression is handled as an alias for the result column that it has been
3147
+ matched against. Otherwise, the next SELECT to the right is tried, and so on.
3148
+ If no matching expression can be found in the result columns of any
3149
+ constituent SELECT, it is an error. Each term of the ORDER BY clause is
3150
+ processed separately and may be matched against result columns from different
3151
+ SELECT statements in the compound.
3152
+ 5. The LIMIT clause
3153
+ The LIMIT clause is used to place an upper bound on the number of rows
3154
+ returned by the entire SELECT statement.
3155
+ In a compound SELECT , only the
3156
+ last or right-most simple SELECT may contain a LIMIT clause.
3157
+ In a compound SELECT ,
3158
+ the LIMIT clause applies to the entire compound, not just the final SELECT.
3159
+ If the right-most simple SELECT is a VALUES clause then no LIMIT clause
3160
+ is allowed.
3161
+ Any scalar expression may be used in the
3162
+ LIMIT clause, so long as it evaluates to an integer or a value that can be
3163
+ losslessly converted to an integer. If the expression evaluates to a NULL
3164
+ value or any other value that cannot be losslessly converted to an integer, an
3165
+ error is returned. If the LIMIT expression evaluates to a negative value,
3166
+ then there is no upper bound on the number of rows returned. Otherwise, the
3167
+ SELECT returns the first N rows of its result set only, where N is the value
3168
+ that the LIMIT expression evaluates to. Or, if the SELECT statement would
3169
+ return less than N rows without a LIMIT clause, then the entire result set is
3170
+ returned.
3171
+ The expression attached to the optional OFFSET clause that may follow a
3172
+ LIMIT clause must also evaluate to an integer, or a value that can be
3173
+ losslessly converted to an integer. If an expression has an OFFSET clause,
3174
+ then the first M rows are omitted from the result set returned by the SELECT
3175
+ statement and the next N rows are returned, where M and N are the values that
3176
+ the OFFSET and LIMIT clauses evaluate to, respectively. Or, if the SELECT
3177
+ would return less than M+N rows if it did not have a LIMIT clause, then the
3178
+ first M rows are skipped and the remaining rows (if any) are returned. If the
3179
+ OFFSET clause evaluates to a negative value, the results are the same as if it
3180
+ had evaluated to zero.
3181
+ Instead of a separate OFFSET clause, the LIMIT clause may specify two
3182
+ scalar expressions separated by a comma. In this case, the first expression
3183
+ is used as the OFFSET expression and the second as the LIMIT expression.
3184
+ This is counter-intuitive, as when using the OFFSET clause the second of
3185
+ the two expressions is the OFFSET and the first the LIMIT.
3186
+ This reversal of the offset and limit is intentional
3187
+ - it maximizes compatibility with other SQL database systems.
3188
+ However, to avoid confusion, programmers are strongly encouraged to use
3189
+ the form of the LIMIT clause that uses the "OFFSET" keyword and avoid
3190
+ using a LIMIT clause with a comma-separated offset.
3191
+ 6. The VALUES clause
3192
+ The phrase "VALUES( expr-list )" means the same thing
3193
+ as "SELECT expr-list ". The phrase
3194
+ "VALUES( expr-list-1 ),...,( expr-list-N )" means the same
3195
+ thing as "SELECT expr-list-1 UNION ALL ... UNION ALL
3196
+ SELECT expr-list-N ". Both forms are the same, except that
3197
+ the number of SELECT statements in a compound is limited by
3198
+ SQLITE_LIMIT_COMPOUND_SELECT whereas the number of rows in a
3199
+ VALUES clause has no arbitrary limit.
3200
+ There are some restrictions on the use of a VALUES clause that are
3201
+ not shown on the syntax diagrams:
3202
+ A VALUES clause cannot be followed by ORDER BY .
3203
+ A VALUES clause cannot be followed by LIMIT .
3204
+ 7. The WITH Clause
3205
+ SELECT statements may be optionally preceded by a single
3206
+ WITH clause that defines one or more common table expressions
3207
+ for use within the SELECT statement.
3208
+ 8. Table-valued Functions In The FROM Clause
3209
+ A virtual table that contains hidden columns can be used like
3210
+ a table-valued function in the FROM clause. The arguments to the
3211
+ table-valued function become constraints on the HIDDEN columns of
3212
+ the virtual table. Additional information can be found in the
3213
+ virtual table documentation .
3214
+ 9. Deviations From Standard SQL
3215
+ The SELECT syntax of SQLite differs slightly from standard SQL.
3216
+ These differences are due to several reasons:
3217
+ In the mid-2000s, there was a lot of emphasis on keeping the library
3218
+ footprint as small as possible, so as not to use too much space
3219
+ on memory-limited flip-phones and similar.
3220
+ During the early years of SQLite, the lead developer sought to follow
3221
+ Postel's Law and to
3222
+ be forgiving and flexible in what input was accepted.
3223
+ There were bugs in early SQLite parsers that accepts some strange inputs.
3224
+ The lead developer's knowledge of SQL was imperfect.
3225
+ Whatever the origin of the input quirks, we generally avoid trying to "fix" them,
3226
+ as any new restrictions on the input syntax would likely cause at least some of
3227
+ the millions of applications that use SQLite to break. We do not want that.
3228
+ The goal of the SQLite development team is to preserve backwards compability to
3229
+ the fullest extent possible. Hence, if a syntax quirk is harmless,
3230
+ we leave it alone and document it here, rather than try to fix it.
3231
+ 9.1. Strange JOIN names
3232
+ SQLite accepts all of the usual syntax for JOIN operators:
3233
+ join-operator:
3234
+ hide
3235
+ NATURAL
3236
+ LEFT
3237
+ OUTER
3238
+ JOIN
3239
+ ,
3240
+ RIGHT
3241
+ FULL
3242
+ INNER
3243
+ CROSS
3244
+ But it does not stop there. SQLite is actually very flexible in how you
3245
+ specify a join operator. The general syntax is:
3246
+ blah blah blah JOIN
3247
+ Where there are between 1 and 3 instances of " blah ", each of which can be
3248
+ any of "CROSS", "FULL", "INNER", "LEFT", "NATURAL", "OUTER", or "RIGHT". The SQLite
3249
+ parser treats each of these keywords as an attribute of the join, which can be combined
3250
+ in any order. This creates the possibility of many new and creative join types beyond
3251
+ what is specified by the syntax diagram. Some of these non-standard join types are
3252
+ specifically disallowed. For example, you cannot say "INNER OUTER JOIN", because
3253
+ that would be contradictory. But you can say things like "OUTER LEFT NATURAL JOIN"
3254
+ which means the same as "NATURAL LEFT OUTER JOIN". Or you can say "LEFT RIGHT JOIN"
3255
+ which is the same as "FULL JOIN".
3256
+ Remember: you can use these non-standard join types but you ought not .
3257
+ Stick to using standard JOIN syntax for portability with other SQL database engines.
3258
+ 9.2. Flexible join syntax
3259
+ Standard SQL has tighter restrictions on join syntax than does SQLite.
3260
+ In standard SQL, all joins other than comma-joins, CROSS JOINs, and NATURAL
3261
+ joins must have either an ON clause or a USING clause and comma-joins, CROSS JOINs,
3262
+ and NATURAL joins must not have either an ON or USING clause. SQLite is not
3263
+ nearly so fussy about join syntax. SQLite will accept and process an ON or USING clause
3264
+ on a comma-join or CROSS JOIN, and will let you omit the ON or USING
3265
+ clause from any join at all. In SQLite, the only restrictions are:
3266
+ You cannot have an ON or USING clause on a NATURAL join.
3267
+ You cannot have both an ON clause and a USING clause on the same join.
3268
+ SQLite even allows you to omit the ON or USING clause from an outer join,
3269
+ though doing so means that the outer join is unconstrained (as if the ON clause
3270
+ where " ON true ") which make the outer join behave like an inner join.
3271
+ 9.3. Precedence of comma-joins and CROSS JOIN
3272
+ In standard SQL, joins that use the JOIN keyword take higher precedence
3273
+ than comma-joins. That is to say, JOIN operators happen before comma operators.
3274
+ This is not the case in SQLite, where all joins have the same precedence.
3275
+ Consider this example:
3276
+ In standard SQL, the FULL JOIN between t2 and t3 would occur first, and
3277
+ then the result of the left join would be cross-joined against t1. But SQLite
3278
+ always handles all joins from left to right. Thus, SQLite will do a cross
3279
+ join on t1 and t2 first, then the result of that cross join will feed into the FULL JOIN
3280
+ with t3. Inner joins are inherently associative, so the difference is only
3281
+ evident if your FROM clause contains one or more outer joins.
3282
+ You can work around this, and make your SQL statements portable across all
3283
+ systems, by observing the following stylistic rules:
3284
+ Do not mix comma-joins with the JOIN keyword. It is fine to use comma-joins,
3285
+ but if you do, the you should use only comma-joins for the entire FROM clause.
3286
+ Prefer LEFT JOIN over other outer join operators.
3287
+ When in doubt, use parentheses to specify the exact join order that you intend.
3288
+ Any one of these suggestions is sufficient to avoid problems, and most
3289
+ programmers instinctively follow all of these suggestions without having to
3290
+ be told, and so the lack of precedence difference between comma-joins and
3291
+ the JOIN keyword in SQLite rarely comes up in practice. But you should be aware
3292
+ of the problem, in case it ever does appear.
3293
+ This page was last updated on 2026-01-26 15:45:07Z