lang.tcl 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270
  1. #
  2. # Run this Tcl script to generate the sqlite.html file.
  3. #
  4. set rcsid {$Id: lang.tcl,v 1.40 2002/06/12 22:33:54 drh Exp $}
  5. puts {<html>
  6. <head>
  7. <title>Query Language Understood By SQLite</title>
  8. </head>
  9. <body bgcolor=white>
  10. <h1 align=center>
  11. SQL As Understood By SQLite
  12. </h1>}
  13. puts "<p align=center>
  14. (This page was last modified on [lrange $rcsid 3 4] UTC)
  15. </p>"
  16. puts {
  17. <p>The SQLite library understands most of the standard SQL
  18. language. But it does omit some features while at the same time
  19. adding a few features of its own. This document attempts to
  20. describe percisely what parts of the SQL language SQLite does
  21. and does not support.</p>
  22. <p>In all of the syntax diagrams that follow, literal text is shown in
  23. bold blue. Non-terminal symbols are shown in italic red. Operators
  24. that are part of the syntactic markup itself are shown in black roman.</p>
  25. <p>This document is just an overview of the SQL syntax implemented
  26. by SQLite. Many low-level productions are omitted. For detailed information
  27. on the language that SQLite understands, refer to the source code.</p>
  28. <p>SQLite implements the follow syntax:</p>
  29. <p><ul>
  30. }
  31. foreach {section} [lsort -index 0 -dictionary {
  32. {{CREATE TABLE} createtable}
  33. {{CREATE INDEX} createindex}
  34. {VACUUM vacuum}
  35. {{DROP TABLE} droptable}
  36. {{DROP INDEX} dropindex}
  37. {INSERT insert}
  38. {REPLACE replace}
  39. {DELETE delete}
  40. {UPDATE update}
  41. {SELECT select}
  42. {COPY copy}
  43. {EXPLAIN explain}
  44. {expression expr}
  45. {{BEGIN TRANSACTION} transaction}
  46. {PRAGMA pragma}
  47. {{ON CONFLICT clause} conflict}
  48. {{CREATE VIEW} createview}
  49. {{DROP VIEW} dropview}
  50. {{CREATE TRIGGER} createtrigger}
  51. {{DROP TRIGGER} droptrigger}
  52. }] {
  53. puts "<li><a href=\"#[lindex $section 1]\">[lindex $section 0]</a></li>"
  54. }
  55. puts {</ul></p>
  56. <p>Details on the implementation of each command are provided in
  57. the sequel.</p>
  58. }
  59. proc Syntax {args} {
  60. puts {<table cellpadding="10">}
  61. foreach {rule body} $args {
  62. puts "<tr><td align=\"right\" valign=\"top\">"
  63. puts "<i><font color=\"#ff3434\">$rule</font></i>&nbsp;::=</td>"
  64. regsub -all < $body {%LT} body
  65. regsub -all > $body {%GT} body
  66. regsub -all %LT $body {</font></b><i><font color="#ff3434">} body
  67. regsub -all %GT $body {</font></i><b><font color="#2c2cf0">} body
  68. regsub -all {[]|[*?]} $body {</font></b>&<b><font color="#2c2cf0">} body
  69. regsub -all "\n" [string trim $body] "<br>\n" body
  70. regsub -all "\n *" $body "\n\\&nbsp;\\&nbsp;\\&nbsp;\\&nbsp;" body
  71. regsub -all {[|,.*()]} $body {<big>&</big>} body
  72. regsub -all { = } $body { <big>=</big> } body
  73. regsub -all {STAR} $body {<big>*</big>} body
  74. puts "<td><b><font color=\"#2c2cf0\">$body</font></b></td></tr>"
  75. }
  76. puts {</table>}
  77. }
  78. proc Operator {name} {
  79. return "<font color=\"#2c2cf0\"><big>$name</big></font>"
  80. }
  81. proc Nonterminal {name} {
  82. return "<i><font color=\"#ff3434\">$name</font></i>"
  83. }
  84. proc Keyword {name} {
  85. return "<font color=\"#2c2cf0\">$name</font>"
  86. }
  87. proc Section {name {label {}}} {
  88. puts "\n<hr />"
  89. if {$label!=""} {
  90. puts "<a name=\"$label\">"
  91. }
  92. puts "<h1>$name</h1>\n"
  93. }
  94. proc Example {text} {
  95. puts "<blockquote><pre>$text</pre></blockquote>"
  96. }
  97. Section {BEGIN TRANSACTION} createindex
  98. Syntax {sql-statement} {
  99. BEGIN [TRANSACTION [<name>]] [ON CONFLICT <conflict-algorithm>]
  100. }
  101. Syntax {sql-statement} {
  102. END [TRANSACTION [<name>]]
  103. }
  104. Syntax {sql-statement} {
  105. COMMIT [TRANSACTION [<name>]]
  106. }
  107. Syntax {sql-statement} {
  108. ROLLBACK [TRANSACTION [<name>]]
  109. }
  110. puts {
  111. <p>Beginning in version 2.0, SQLite supports transactions with
  112. rollback and atomic commit.</p>
  113. <p>
  114. No changes can be made to the database except within a transaction.
  115. Any command that changes the database (basically, any SQL command
  116. other than SELECT) will automatically starts a transaction if
  117. one is not already in effect. Automatically stared transactions
  118. are committed at the conclusion of the command.
  119. </p>
  120. <p>
  121. Transactions can be started manually using the BEGIN
  122. command. Such transactions usually persist until the next
  123. COMMIT or ROLLBACK command. But a transaction will also
  124. ROLLBACK if the database is closed or if an error occurs
  125. and the ROLLBACK conflict resolution algorithm is specified.
  126. See the documention on the <a href="#conflict">ON CONFLICT</a>
  127. clause for additional information about the ROLLBACK
  128. conflict resolution algorithm.
  129. </p>
  130. <p>
  131. The optional ON CONFLICT clause at the end of a BEGIN statement
  132. can be used to changed the default conflict resolution algorithm.
  133. The normal default is ABORT. If an alternative is specified by
  134. the ON CONFLICT clause of a BEGIN, then that alternative is used
  135. as the default for all commands within the transaction. The default
  136. algorithm is overridden by ON CONFLICT clauses on individual
  137. constraints within the CREATE TABLE or CREATE INDEX statements
  138. and by the OR clauses on COPY, INSERT, and UPDATE commands.
  139. </p>
  140. }
  141. Section COPY copy
  142. Syntax {sql-statement} {
  143. COPY [ OR <conflict-algorithm> ] <table-name> FROM <filename>
  144. [ USING DELIMITERS <delim> ]
  145. }
  146. puts {
  147. <p>The COPY command is an extension used to load large amounts of
  148. data into a table. It is modeled after a similar command found
  149. in PostgreSQL. In fact, the SQLite COPY command is specifically
  150. designed to be able to read the output of the PostgreSQL dump
  151. utility <b>pg_dump</b> so that data can be easily transferred from
  152. PostgreSQL into SQLite.<p>
  153. <p>The table-name is the name of an existing table which is to
  154. be filled with data. The filename is a string or identifier that
  155. names a file from which data will be read. The filename can be
  156. the <b>STDIN</b> to read data from standard input.<p>
  157. <p>Each line of the input file is converted into a single record
  158. in the table. Columns are separated by tabs. If a tab occurs as
  159. data within a column, then that tab is preceded by a baskslash "\"
  160. character. A baskslash in the data appears as two backslashes in
  161. a row. The optional USING DELIMITERS clause can specify a delimiter
  162. other than tab.</p>
  163. <p>If a column consists of the character "\N", that column is filled
  164. with the value NULL.</p>
  165. <p>The optional conflict-clause allows the specification of an alternative
  166. constraint conflict resolution algorithm to use for this one command.
  167. See the section titled
  168. <a href="#conflict">ON CONFLICT</a> for additional information.</p>
  169. <p>When the input data source is STDIN, the input can be terminated
  170. by a line that contains only a baskslash and a dot:}
  171. puts "\"[Operator \\.]\".</p>"
  172. Section {CREATE INDEX} createindex
  173. Syntax {sql-statement} {
  174. CREATE [UNIQUE] INDEX <index-name>
  175. ON <table-name> ( <column-name> [, <column-name>]* )
  176. [ ON CONFLICT <conflict-algorithm> ]
  177. } {column-name} {
  178. <name> [ ASC | DESC ]
  179. }
  180. puts {
  181. <p>The CREATE INDEX command consists of the keywords "CREATE INDEX" followed
  182. by the name of the new index, the keyword "ON", the name of a previously
  183. created table that is to be indexed, and a parenthesized list of names of
  184. columns in the table that are used for the index key.
  185. Each column name can be followed by one of the "ASC" or "DESC" keywords
  186. to indicate sort order, but the sort order is ignored in the current
  187. implementation.</p>
  188. <p>There are no arbitrary limits on the number of indices that can be
  189. attached to a single table, nor on the number of columns in an index.</p>
  190. <p>If the UNIQUE keyword appears between CREATE and INDEX then duplicate
  191. index entries are not allowed. Any attempt to insert a duplicate entry
  192. will result in a rollback and an error message.</p>
  193. <p>The optional conflict-clause allows the specification of al alternative
  194. default constraint conflict resolution algorithm for this index.
  195. This only makes sense if the UNIQUE keyword is used since otherwise
  196. there are not constraints on the index. The default algorithm is
  197. ABORT. If a COPY, INSERT, or UPDATE statement specifies a particular
  198. conflict resolution algorithm, that algorithm is used in place of
  199. the default algorithm specified here.
  200. See the section titled
  201. <a href="#conflict">ON CONFLICT</a> for additional information.</p>
  202. <p>The exact text
  203. of each CREATE INDEX statement is stored in the <b>sqlite_master</b>
  204. table. Everytime the database is opened, all CREATE INDEX statements
  205. are read from the <b>sqlite_master</b> table and used to regenerate
  206. SQLite's internal representation of the index layout.</p>
  207. }
  208. Section {CREATE TABLE} {createtable}
  209. Syntax {sql-command} {
  210. CREATE [TEMP | TEMPORARY] TABLE <table-name> (
  211. <column-def> [, <column-def>]*
  212. [, <constraint>]*
  213. )
  214. } {sql-command} {
  215. CREATE [TEMP | TEMPORARY] TABLE <table-name> AS <select-statement>
  216. } {column-def} {
  217. <name> [<type>] [<column-constraint>]*
  218. } {type} {
  219. <typename> |
  220. <typename> ( <number> ) |
  221. <typename> ( <number> , <number> )
  222. } {column-constraint} {
  223. NOT NULL [ <conflict-clause> ] |
  224. PRIMARY KEY [<sort-order>] [ <conflict-clause> ] |
  225. UNIQUE [ <conflict-clause> ] |
  226. CHECK ( <expr> ) [ <conflict-clause> ] |
  227. DEFAULT <value>
  228. } {constraint} {
  229. PRIMARY KEY ( <name> [, <name>]* ) [ <conflict-clause> ]|
  230. UNIQUE ( <name> [, <name>]* ) [ <conflict-clause> ] |
  231. CHECK ( <expr> ) [ <conflict-clause> ]
  232. } {conflict-clause} {
  233. ON CONFLICT <conflict-algorithm>
  234. }
  235. puts {
  236. <p>A CREATE TABLE statement is basically the keywords "CREATE TABLE"
  237. followed by the name of a new table and a parenthesized list of column
  238. definitions and constraints. The table name can be either an identifier
  239. or a string. The only reserved table name is "<b>sqlite_master</b>" which
  240. is the name of the table that records the database schema.</p>
  241. <p>Each column definition is the name of the column followed by the
  242. datatype for that column, then one or more optional column constraints.
  243. The datatype for the column is (usually) ignored and may be omitted.
  244. All information is stored as null-terminated strings.
  245. The UNIQUE constraint causes an index to be created on the specified
  246. columns. This index must contain unique keys.
  247. The DEFAULT constraint
  248. specifies a default value to use when doing an INSERT.
  249. </p>
  250. <p>Specifying a PRIMARY KEY normally just creates a UNIQUE index
  251. on the primary key. However, if primary key is on a single column
  252. that has datatype INTEGER, then that column is used internally
  253. as the actual key of the B-Tree for the table. This means that the column
  254. may only hold unique integer values. (Except for this one case,
  255. SQLite ignores the datatype specification of columns and allows
  256. any kind of data to be put in a column regardless of its declared
  257. datatype.) If a table does not have an INTEGER PRIMARY KEY column,
  258. then the B-Tree key will be a automatically generated integer. The
  259. B-Tree key for a row can always be accessed using one of the
  260. special names "<b>ROWID</b>", "<b>OID</b>", or "<b>_ROWID_</b>".
  261. This is true regardless of whether or not there is an INTEGER
  262. PRIMARY KEY.</p>
  263. <p>If the "TEMP" or "TEMPORARY" keyword occurs in between "CREATE"
  264. and "TABLE" then the table that is created is only visible to the
  265. process that opened the database and is automatically deleted when
  266. the database is closed. Any indices created on a temporary table
  267. are also temporary. Temporary tables and indices are stored in a
  268. separate file distinct from the main database file.</p>
  269. <p>The optional conflict-clause following each constraint
  270. allows the specification of an alternative default
  271. constraint conflict resolution algorithm for that constraint.
  272. The default is abort ABORT. Different constraints within the same
  273. table may have different default conflict resolution algorithms.
  274. If an COPY, INSERT, or UPDATE command specifies a different conflict
  275. resolution algorithm, then that algorithm is used in place of the
  276. default algorithm specified in the CREATE TABLE statement.
  277. See the section titled
  278. <a href="#conflict">ON CONFLICT</a> for additional information.</p>
  279. <p>CHECK constraints are ignored in the current implementation.
  280. Support for CHECK constraints may be added in the future. As of
  281. version 2.3.0, NOT NULL, PRIMARY KEY, and UNIQUE constraints all
  282. work.</p>
  283. <p>There are no arbitrary limits on the number
  284. of columns or on the number of constraints in a table.
  285. The total amount of data in a single row is limited to about
  286. 1 megabytes. (This limit can be increased to 16MB by changing
  287. a single #define in the source code and recompiling.)</p>
  288. <p>The CREATE TABLE AS form defines the table to be
  289. the result set of a query. The names of the table columns are
  290. the names of the columns in the result.</p>
  291. <p>The exact text
  292. of each CREATE TABLE statement is stored in the <b>sqlite_master</b>
  293. table. Everytime the database is opened, all CREATE TABLE statements
  294. are read from the <b>sqlite_master</b> table and used to regenerate
  295. SQLite's internal representation of the table layout.
  296. If the original command was a CREATE TABLE AS then then an equivalent
  297. CREATE TABLE statement is synthesized and store in <b>sqlite_master</b>
  298. in place of the original command.
  299. </p>
  300. }
  301. Section {CREATE TRIGGER} createtrigger
  302. Syntax {sql-statement} {
  303. CREATE TRIGGER <trigger-name> [ BEFORE | AFTER ]
  304. <database-event> ON <table-name>
  305. <trigger-action>
  306. }
  307. Syntax {sql-statement} {
  308. CREATE TRIGGER <trigger-name> INSTEAD OF
  309. <database-event> ON <view-name>
  310. <trigger-action>
  311. }
  312. Syntax {database-event} {
  313. DELETE |
  314. INSERT |
  315. UPDATE |
  316. UPDATE OF <column-list>
  317. }
  318. Syntax {trigger-action} {
  319. [ FOR EACH ROW ] [ WHEN <expression> ]
  320. BEGIN
  321. <trigger-step> ; [ <trigger-step> ; ]*
  322. END
  323. }
  324. Syntax {trigger-step} {
  325. <update-statement> | <insert-statement> |
  326. <delete-statement> | <select-statement>
  327. }
  328. puts {
  329. <p>The CREATE TRIGGER statement is used to add triggers to the
  330. database schema. Triggers are database operations (the <i>trigger-action</i>)
  331. that are automatically performed when a specified database event (the
  332. <i>database-event</i>) occurs. </p>
  333. <p>A trigger may be specified to fire whenever a DELETE, INSERT or UPDATE of a
  334. particular database table occurs, or whenever an UPDATE of one or more
  335. specified columns of a table are updated.</p>
  336. <p>At this time SQLite supports only FOR EACH ROW triggers, not FOR EACH
  337. STATEMENT triggers. Hence explicitly specifying FOR EACH ROW is optional. FOR
  338. EACH ROW implies that the SQL statements specified as <i>trigger-steps</i>
  339. may be executed (depending on the WHEN clause) for each database row being
  340. inserted, updated or deleted by the statement causing the trigger to fire.</p>
  341. <p>Both the WHEN clause and the <i>trigger-steps</i> may access elements of
  342. the row being inserted, deleted or updated using references of the form
  343. "NEW.<i>column-name</i>" and "OLD.<i>column-name</i>", where
  344. <i>column-name</i> is the name of a column from the table that the trigger
  345. is associated with. OLD and NEW references may only be used in triggers on
  346. <i>trigger-event</i>s for which they are relevant, as follows:</p>
  347. <table border=0 cellpadding=10>
  348. <tr>
  349. <td valign="top" align="right" width=120><i>INSERT</i></td>
  350. <td valign="top">NEW references are valid</td>
  351. </tr>
  352. <tr>
  353. <td valign="top" align="right" width=120><i>UPDATE</i></td>
  354. <td valign="top">NEW and OLD references are valid</td>
  355. </tr>
  356. <tr>
  357. <td valign="top" align="right" width=120><i>DELETE</i></td>
  358. <td valign="top">OLD references are valid</td>
  359. </tr>
  360. </table>
  361. </p>
  362. <p>If a WHEN clause is supplied, the SQL statements specified as <i>trigger-steps</i> are only executed for rows for which the WHEN clause is true. If no WHEN clause is supplied, the SQL statements are executed for all rows.</p>
  363. <p>The specified <i>trigger-time</i> determines when the <i>trigger-steps</i>
  364. will be executed relative to the insertion, modification or removal of the
  365. associated row.</p>
  366. <p>An ON CONFLICT clause may be specified as part of an UPDATE or INSERT
  367. <i>trigger-step</i>. However if an ON CONFLICT clause is specified as part of
  368. the statement causing the trigger to fire, then this conflict handling
  369. policy is used instead.</p>
  370. <p>Triggers are automatically dropped when the table that they are
  371. associated with is dropped.</p>
  372. <p>Triggers may be created on views, as well as ordinary tables, by specifying
  373. INSTEAD OF in the CREATE TRIGGER statement. If one or more ON INSERT, ON DELETE
  374. or ON UPDATE triggers are defined on a view, then it is not an error to execute
  375. an INSERT, DELETE or UPDATE statement on the view, respectively. Thereafter,
  376. executing an INSERT, DELETE or UPDATE on the view causes the associated
  377. triggers to fire. The real tables underlying the view are not modified
  378. (except possibly explicitly, by a trigger program).</p>
  379. <p><b>Example:</b></p>
  380. <p>Assuming that customer records are stored in the "customers" table, and
  381. that order records are stored in the "orders" table, the following trigger
  382. ensures that all associated orders are redirected when a customer changes
  383. his or her address:</p>
  384. }
  385. Example {
  386. CREATE TRIGGER update_customer_address UPDATE OF address ON customers
  387. BEGIN
  388. UPDATE orders SET address = new.address WHERE customer_name = old.name;
  389. END;
  390. }
  391. puts {
  392. <p>With this trigger installed, executing the statement:</p>
  393. }
  394. Example {
  395. UPDATE customers SET address = '1 Main St.' WHERE name = 'Jack Jones';
  396. }
  397. puts {
  398. <p>causes the following to be automatically executed:</p>
  399. }
  400. Example {
  401. UPDATE orders SET address = '1 Main St.' WHERE customer_name = 'Jack Jones';
  402. }
  403. puts {
  404. <p>Note that currently, triggers may behave oddly when created on tables
  405. with INTEGER PRIMARY KEY fields. If a BEFORE trigger program modifies the
  406. INTEGER PRIMARY KEY field of a row that will be subsequently updated by the
  407. statement that causes the trigger to fire, then the update may not occur.
  408. The workaround is to declare the table with a PRIMARY KEY column instead
  409. of an INTEGER PRIMARY KEY column.</p>
  410. }
  411. puts {
  412. <p>A special SQL function RAISE() may be used within a trigger-program, with the following syntax</p>
  413. }
  414. Syntax {raise-function} {
  415. RAISE ( ABORT, <error-message> ) |
  416. RAISE ( FAIL, <error-message> ) |
  417. RAISE ( ROLLBACK, <error-message> ) |
  418. RAISE ( IGNORE )
  419. }
  420. puts {
  421. <p>When one of the first three forms is called during trigger-program execution, the specified ON CONFLICT processing is performed (either ABORT, FAIL or
  422. ROLLBACK) and the current query terminates. An error code of SQLITE_CONSTRAINT is returned to the user, along with the specified error message.</p>
  423. <p>When RAISE(IGNORE) is called, the remainder of the current trigger program,
  424. the statement that caused the trigger program to execute and any subsequent
  425. trigger programs that would of been executed are abandoned. No database
  426. changes are rolled back. If the statement that caused the trigger program
  427. to execute is itself part of a trigger program, then that trigger program
  428. resumes execution at the beginning of the next step.
  429. </p>
  430. }
  431. Section {CREATE VIEW} {createview}
  432. Syntax {sql-command} {
  433. CREATE VIEW <view-name> AS <select-statement>
  434. }
  435. puts {
  436. <p>The CREATE VIEW command assigns a name to a pre-packaged SELECT
  437. statement. Once the view is created, it can be used in the FROM clause
  438. of another SELECT in place of a table name.
  439. </p>
  440. <p>You cannot COPY, INSERT or UPDATE a view. Views are read-only.</p>
  441. }
  442. Section DELETE delete
  443. Syntax {sql-statement} {
  444. DELETE FROM <table-name> [WHERE <expr>]
  445. }
  446. puts {
  447. <p>The DELETE command is used to remove records from a table.
  448. The command consists of the "DELETE FROM" keywords followed by
  449. the name of the table from which records are to be removed.
  450. </p>
  451. <p>Without a WHERE clause, all rows of the table are removed.
  452. If a WHERE clause is supplied, then only those rows that match
  453. the expression are removed.</p>
  454. }
  455. Section {DROP INDEX} dropindex
  456. Syntax {sql-command} {
  457. DROP INDEX <index-name>
  458. }
  459. puts {
  460. <p>The DROP INDEX statement consists of the keywords "DROP INDEX" followed
  461. by the name of the index. The index named is completely removed from
  462. the disk. The only way to recover the index is to reenter the
  463. appropriate CREATE INDEX command.</p>
  464. }
  465. Section {DROP TABLE} droptable
  466. Syntax {sql-command} {
  467. DROP TABLE <table-name>
  468. }
  469. puts {
  470. <p>The DROP TABLE statement consists of the keywords "DROP TABLE" followed
  471. by the name of the table. The table named is completely removed from
  472. the disk. The table can not be recovered. All indices associated with
  473. the table are also deleted.</p>}
  474. Section {DROP TRIGGER} droptrigger
  475. Syntax {sql-statement} {
  476. DROP TRIGGER <trigger-name>
  477. }
  478. puts {
  479. <p>Used to drop a trigger from the database schema. Note that triggers
  480. are automatically dropped when the associated table is dropped.</p>
  481. }
  482. Section {DROP VIEW} dropview
  483. Syntax {sql-command} {
  484. DROP VIEW <view-name>
  485. }
  486. puts {
  487. <p>The DROP VIEW statement consists of the keywords "DROP VIEW" followed
  488. by the name of the view. The view named is removed from the database.
  489. But no actual data is modified.</p>}
  490. Section EXPLAIN explain
  491. Syntax {sql-statement} {
  492. EXPLAIN <sql-statement>
  493. }
  494. puts {
  495. <p>The EXPLAIN command modifier is a non-standard extension. The
  496. idea comes from a similar command found in PostgreSQL, but the operation
  497. is completely different.</p>
  498. <p>If the EXPLAIN keyword appears before any other SQLite SQL command
  499. then instead of actually executing the command, the SQLite library will
  500. report back the sequence of virtual machine instructions it would have
  501. used to execute the command had the EXPLAIN keyword not been present.
  502. For additional information about virtual machine instructions see
  503. the <a href="arch.html">architecture description</a> or the documentation
  504. on <a href="opcode.html">available opcodes</a> for the virtual machine.</p>
  505. }
  506. Section expression expr
  507. Syntax {expr} {
  508. <expr> <binary-op> <expr> |
  509. <expr> <like-op> <expr> |
  510. <unary-op> <expr> |
  511. ( <expr> ) |
  512. <column-name> |
  513. <table-name> . <column-name> |
  514. <literal-value> |
  515. <function-name> ( <expr-list> | STAR ) |
  516. <expr> ISNULL |
  517. <expr> NOTNULL |
  518. <expr> [NOT] BETWEEN <expr> AND <expr> |
  519. <expr> [NOT] IN ( <value-list> ) |
  520. <expr> [NOT] IN ( <select-statement> ) |
  521. ( <select-statement> ) |
  522. CASE [<expr>] ( WHEN <expr> THEN <expr> )+ [ELSE <expr>] END
  523. } {like-op} {
  524. LIKE | GLOB | NOT LIKE | NOT GLOB
  525. }
  526. puts {
  527. <p>This section is different from the others. Most other sections of
  528. this document talks about a particular SQL command. This section does
  529. not talk about a standalone command but about "expressions" which are
  530. subcomponent of most other commands.</p>
  531. <p>SQLite understands the following binary operators, in order from
  532. highest to lowest precedence:</p>
  533. <blockquote><pre>
  534. <font color="#2c2cf0"><big>||
  535. * / %
  536. + -
  537. &lt;&lt; &gt;&gt; &amp; |
  538. &lt; &lt;= &gt; &gt;=
  539. = == != &lt;&gt; </big>IN
  540. AND
  541. OR</font>
  542. </pre></blockquote>
  543. <p>Supported unary operaters are these:</p>
  544. <blockquote><pre>
  545. <font color="#2c2cf0"><big>- + ! ~</big></font>
  546. </pre></blockquote>
  547. <p>Any SQLite value can be used as part of an expression.
  548. For arithmetic operations, integers are treated as integers.
  549. Strings are first converted to real numbers using <b>atof()</b>.
  550. For comparison operators, numbers compare as numbers and strings
  551. compare as strings. For string comparisons, case is significant
  552. but is only used to break a tie.
  553. Note that there are two variations of the equals and not equals
  554. operators. Equals can be either}
  555. puts "[Operator =] or [Operator ==].
  556. The non-equals operator can be either
  557. [Operator !=] or [Operator {&lt;&gt;}].
  558. The [Operator ||] operator is \"concatenate\" - it joins together
  559. the two strings of its operands.</p>"
  560. puts {
  561. <p>The LIKE operator does a wildcard comparision. The operand
  562. to the right contains the wildcards.}
  563. puts "A percent symbol [Operator %] in the right operand
  564. matches any sequence of zero or more characters on the left.
  565. An underscore [Operator _] on the right
  566. matches any single character on the left."
  567. puts {The LIKE operator is
  568. not case sensitive and will match upper case characters on one
  569. side against lower case characters on the other.
  570. (A bug: SQLite only understands upper/lower case for 7-bit Latin
  571. characters. Hence the LIKE operator is case sensitive for
  572. 8-bit iso8859 characters or UTF-8 characters. For example,
  573. the expression <b>'a'&nbsp;LIKE&nbsp;'A'</b> is TRUE but
  574. <b>'&aelig;'&nbsp;LIKE&nbsp;'&AElig;'</b> is FALSE.)
  575. </p>
  576. <p>The GLOB operator is similar to LIKE but uses the Unix
  577. file globbing syntax for its wildcards. Also, GLOB is case
  578. sensitive, unlike LIKE. Both GLOB and LIKE may be preceded by
  579. the NOT keyword to invert the sense of the test.</p>
  580. <p>A column name can be any of the names defined in the CREATE TABLE
  581. statement or one of the following special identifiers: "<b>ROWID</b>",
  582. "<b>OID</b>", or "<b>_ROWID_</b>".
  583. These special identifiers all describe the
  584. unique random integer key (the "row key") associated with every
  585. row of every table.
  586. The special identifiers only refer to the row key if the CREATE TABLE
  587. statement does not define a real column with the same name. Row keys
  588. act like read-only columns. A row key can be used anywhere a regular
  589. column can be used, except that you cannot change the value
  590. of a row key in an UPDATE or INSERT statement.
  591. "SELECT * ..." does not return the row key.</p>
  592. <p>SELECT statements can appear in expressions as either the
  593. right-hand operand of the IN operator or as a scalar quantity.
  594. In both cases, the SELECT should have only a single column in its
  595. result. Compound SELECTs (connected with keywords like UNION or
  596. EXCEPT) are allowed. Any ORDER BY clause on the select is ignored.
  597. A SELECT in an expression is evaluated once before any other processing
  598. is performed, so none of the expressions within the select itself can
  599. refer to quantities in the containing expression.</p>
  600. <p>When a SELECT is the right operand of the IN operator, the IN
  601. operator returns TRUE if the result of the left operand is any of
  602. the values generated by the select. The IN operator may be preceded
  603. by the NOT keyword to invert the sense of the test.</p>
  604. <p>When a SELECT appears within an expression but is not the right
  605. operand of an IN operator, then the first row of the result of the
  606. SELECT becomes the value used in the expression. If the SELECT yields
  607. more than one result row, all rows after the first are ignored. If
  608. the SELECT yeilds no rows, then the value of the SELECT is NULL.</p>
  609. <p>Both simple and aggregate functions are supported. A simple
  610. function can be used in any expression. Simple functions return
  611. a result immediately based on their inputs. Aggregate functions
  612. may only be used in a SELECT statement. Aggregate functions compute
  613. their result across all rows of the result set.</p>
  614. <p>The following simple functions are currently supported:</p>
  615. <table border=0 cellpadding=10>
  616. <tr>
  617. <td valign="top" align="right" width=120>abs(<i>X</i>)</td>
  618. <td valign="top">Return the absolute value of argument <i>X</i>.</td>
  619. </tr>
  620. <tr>
  621. <td valign="top" align="right">coalesce(<i>X</i>,<i>Y</i>,...)</td>
  622. <td valign="top">Return a copy of the first non-NULL argument. If
  623. all arguments are NULL then NULL is returned.</td>
  624. </tr>
  625. <tr>
  626. <td valign="top" align="right">last_insert_rowid()</td>
  627. <td valign="top">Return the ROWID of the last row insert from this
  628. connection to the database. This is the same value that would be returned
  629. from the <b>sqlite_last_insert_rowid()</b> API function.</td>
  630. </tr>
  631. <tr>
  632. <td valign="top" align="right">length(<i>X</i>)</td>
  633. <td valign="top">Return the string length of <i>X</i> in characters.
  634. If SQLite is configured to support UTF-8, then the number of UTF-8
  635. characters is returned, not the number of bytes.</td>
  636. </tr>
  637. <tr>
  638. <td valign="top" align="right">lower(<i>X</i>)</td>
  639. <td valign="top">Return a copy of string <i>X</i> will all characters
  640. converted to lower case. The C library <b>tolower()</b> routine is used
  641. for the conversion, which means that this function might not
  642. work correctly on UTF-8 characters.</td>
  643. </tr>
  644. <tr>
  645. <td valign="top" align="right">max(<i>X</i>,<i>Y</i>,...)</td>
  646. <td valign="top">Return the argument with the maximum value. Arguments
  647. may be strings in addition to numbers. The maximum value is determined
  648. by the usual sort order. Note that <b>max()</b> is a simple function when
  649. it has 2 or more arguments but converts to an aggregate function if given
  650. only a single argument.</td>
  651. </tr>
  652. <tr>
  653. <td valign="top" align="right">min(<i>X</i>,<i>Y</i>,...)</td>
  654. <td valign="top">Return the argument with the minimum value. Arguments
  655. may be strings in addition to numbers. The mminimum value is determined
  656. by the usual sort order. Note that <b>min()</b> is a simple function when
  657. it has 2 or more arguments but converts to an aggregate function if given
  658. only a single argument.</td>
  659. </tr>
  660. <tr>
  661. <td valign="top" align="right">random(*)</td>
  662. <td valign="top">Return a random integer between -2147483648 and
  663. +2147483647.</td>
  664. </tr>
  665. <tr>
  666. <td valign="top" align="right">round(<i>X</i>)<br>round(<i>X</i>,<i>Y</i>)</td>
  667. <td valign="top">Round off the number <i>X</i> to <i>Y</i> digits to the
  668. right of the decimal point. If the <i>Y</i> argument is omitted, 0 is
  669. assumed.</td>
  670. </tr>
  671. <tr>
  672. <td valign="top" align="right">substr(<i>X</i>,<i>Y</i>,<i>Z</i>)</td>
  673. <td valign="top">Return a substring of input string <i>X</i> that begins
  674. with the <i>Y</i>-th character and which is <i>Z</i> characters long.
  675. The left-most character of <i>X</i> is number 1. If <i>Y</i> is negative
  676. the the first character of the substring is found by counting from the
  677. right rather than the left. If SQLite is configured to support UTF-8,
  678. then characters indices refer to actual UTF-8 characters, not bytes.</td>
  679. </tr>
  680. <tr>
  681. <td valign="top" align="right">upper(<i>X</i>)</td>
  682. <td valign="top">Return a copy of input string <i>X</i> converted to all
  683. upper-case letters. The implementation of this function uses the C library
  684. routine <b>toupper()</b> which means it may not work correctly on
  685. UTF-8 strings.</td>
  686. </tr>
  687. </table>
  688. <p>
  689. The following aggregate functions are supported:
  690. </p>
  691. <table border=0 cellpadding=10>
  692. <tr>
  693. <td valign="top" align="right" width=120>avg(<i>X</i>)</td>
  694. <td valign="top">Return the average value of all <i>X</i> within a group.</td>
  695. </tr>
  696. <tr>
  697. <td valign="top" align="right">count(<i>X</i>)<br>count(*)</td>
  698. <td valign="top">The first form return a count of the number of times
  699. that <i>X</i> is not NULL in a group. The second form (with no argument)
  700. returns the total number of rows in the group.</td>
  701. </tr>
  702. <tr>
  703. <td valign="top" align="right">max(<i>X</i>)</td>
  704. <td valign="top">Return the maximum value of all values in the group.
  705. The usual sort order is used to determine the maximum.</td>
  706. </tr>
  707. <tr>
  708. <td valign="top" align="right">min(<i>X</i>)</td>
  709. <td valign="top">Return the minimum value of all values in the group.
  710. The usual sort order is used to determine the minimum.</td>
  711. </tr>
  712. <tr>
  713. <td valign="top" align="right">sum(<i>X</i>)</td>
  714. <td valign="top">Return the numeric sum of all values in the group.</td>
  715. </tr>
  716. </table>
  717. }
  718. Section INSERT insert
  719. Syntax {sql-statement} {
  720. INSERT [OR <conflict-algorithm>] INTO <table-name> [(<column-list>)] VALUES(<value-list>) |
  721. INSERT [OR <conflict-algorithm>] INTO <table-name> [(<column-list>)] <select-statement>
  722. }
  723. puts {
  724. <p>The INSERT statement comes in two basic forms. The first form
  725. (with the "VALUES" keyword) creates a single new row in an existing table.
  726. If no column-list is specified then the number of values must
  727. be the same as the number of columns in the table. If a column-list
  728. is specified, then the number of values must match the number of
  729. specified columns. Columns of the table that do not appear in the
  730. column list are fill with the default value, or with NULL if not
  731. default value is specified.
  732. </p>
  733. <p>The second form of the INSERT statement takes it data from a
  734. SELECT statement. The number of columns in the result of the
  735. SELECT must exactly match the number of columns in the table if
  736. no column list is specified, or it must match the number of columns
  737. name in the column list. A new entry is made in the table
  738. for every row of the SELECT result. The SELECT may be simple
  739. or compound. If the SELECT statement has an ORDER BY clause,
  740. the ORDER BY is ignored.</p>
  741. <p>The optional conflict-clause allows the specification of an alternative
  742. constraint conflict resolution algorithm to use during this one command.
  743. See the section titled
  744. <a href="#conflict">ON CONFLICT</a> for additional information.
  745. For compatibility with MySQL, the parser allows the use of the
  746. single keyword "REPLACE" as an alias for "INSERT OR REPLACE".
  747. </p>
  748. }
  749. Section {ON CONFLICT clause} conflict
  750. Syntax {conflict-clause} {
  751. ON CONFLICT <conflict-algorithm>
  752. } {conflict-algorithm} {
  753. ROLLBACK | ABORT | FAIL | IGNORE | REPLACE
  754. }
  755. puts {
  756. <p>The ON CONFLICT clause is not a separate SQL command. It is a
  757. non-standard clause that can appear in many other SQL commands.
  758. It is given its own section in this document because it is not
  759. part of standard SQL and therefore might not be familiar.</p>
  760. <p>The syntax for the ON CONFLICT clause is as shown above for
  761. the CREATE TABLE, CREATE INDEX, and BEGIN TRANSACTION commands.
  762. For the COPY, INSERT, and UPDATE commands, the keywords
  763. "ON CONFLICT" are replaced by "OR", to make the syntax seem more
  764. natural. But the meaning of the clause is the same either way.</p>
  765. <p>The ON CONFLICT clause specifies an algorithm used to resolve
  766. constraint conflicts. There are five choices: ROLLBACK, ABORT,
  767. FAIL, IGNORE, and REPLACE. The default algorithm is ABORT. This
  768. is what they mean:</p>
  769. <dl>
  770. <dt><b>ROLLBACK</b></dt>
  771. <dd><p>When a constraint violation occurs, an immediate ROLLBACK
  772. occurs, thus ending the current transaction, and the command aborts
  773. with a return code of SQLITE_CONSTRAINT. If no transaction is
  774. active (other than the implied transaction that is created on every
  775. command) then this algorithm works the same as ABORT.</p></dd>
  776. <dt><b>ABORT</b></dt>
  777. <dd><p>When a constraint violation occurs, the command backs out
  778. any prior changes it might have made and aborts with a return code
  779. of SQLITE_CONSTRAINT. But no ROLLBACK is executed so changes
  780. from prior commands within the same transaction
  781. are preserved. This is the default behavior.</p></dd>
  782. <dt><b>FAIL</b></dt>
  783. <dd><p>When a constraint violation occurs, the command aborts with a
  784. return code SQLITE_CONSTRAINT. But any changes to the database that
  785. the command made prior to encountering the constraint violation
  786. are preserved and are not backed out. For example, if an UPDATE
  787. statement encountered a constraint violation on the 100th row that
  788. it attempts to update, then the first 99 row changes are preserved
  789. but changes to rows 100 and beyond never occur.</p></dd>
  790. <dt><b>IGNORE</b></dt>
  791. <dd><p>When a constraint violation occurs, the one row that contains
  792. the constraint violation is not inserted or changed. But the command
  793. continues executing normally. Other rows before and after the row that
  794. contained the constraint violation continue to be inserted or updated
  795. normally. No error is returned.</p></dd>
  796. <dt><b>REPLACE</b></dt>
  797. <dd><p>When a UNIQUE constraint violation occurs, the pre-existing row
  798. that is causing the constraint violation is removed prior to inserting
  799. or updating the current row. Thus the insert or update always occurs.
  800. The command continues executing normally. No error is returned.</p>
  801. <p>If a NOT NULL constraint violation occurs, the NULL value is replaced
  802. by the default value for that column. If the column has no default
  803. value, then the ABORT algorithm is used.</p>
  804. </dd>
  805. </dl>
  806. <p>
  807. The conflict resolution algorithm can be specified in three places,
  808. in order from lowest to highest precedence:
  809. </p>
  810. <ol>
  811. <li><p>
  812. On a BEGIN TRANSACTION command.
  813. </p></li>
  814. <li><p>
  815. On individual constraints within a CREATE TABLE or CREATE INDEX
  816. statement.
  817. </p></li>
  818. <li><p>
  819. In the OR clause of a COPY, INSERT, or UPDATE command.
  820. </p></li>
  821. </ol>
  822. <p>The algorithm specified in the OR clause of a COPY, INSERT, or UPDATE
  823. overrides any algorithm specified by a CREATE TABLE or CREATE INDEX.
  824. The algorithm specified within a CREATE TABLE or CREATE INDEX will, in turn,
  825. override the algorithm specified by a BEGIN TRANSACTION command.
  826. If no algorithm is specified anywhere, the ABORT algorithm is used.</p>
  827. }
  828. # <p>For additional information, see
  829. # <a href="conflict.html">conflict.html</a>.</p>
  830. Section PRAGMA pragma
  831. Syntax {sql-statement} {
  832. PRAGMA <name> = <value> |
  833. PRAGMA <function>(<arg>)
  834. }
  835. puts {
  836. <p>The PRAGMA command is used to modify the operation of the SQLite library.
  837. The pragma command is experimental and specific pragma statements may
  838. removed or added in future releases of SQLite. Use this command
  839. with caution.</p>
  840. <p>The current implementation supports the following pragmas:</p>
  841. <ul>
  842. <li><p><b>PRAGMA cache_size;
  843. <br>PRAGMA cache_size = </b><i>Number-of-pages</i><b>;</b></p>
  844. <p>Query or change the maximum number of database disk pages that SQLite
  845. will hold in memory at once. Each page uses about 1.5K of memory.
  846. The default cache size is 2000. If you are doing UPDATEs or DELETEs
  847. that change many rows of a database and you do not mind if SQLite
  848. uses more memory, you can increase the cache size for a possible speed
  849. improvement.</p>
  850. <p>When you change the cache size using the cache_size pragma, the
  851. change only endures for the current session. The cache size reverts
  852. to the default value when the database is closed and reopened. Use
  853. the <b>default_cache_size</b> pragma to check the cache size permanently
  854. </p></li>
  855. <li><p><b>PRAGMA count_changes = ON;
  856. <br>PRAGMA count_changes = OFF;</b></p>
  857. <p>When on, the COUNT_CHANGES pragma causes the callback function to
  858. be invoked once for each DELETE, INSERT, or UPDATE operation. The
  859. argument is the number of rows that were changed.</p>
  860. <p>This pragma may be removed from future versions of SQLite.
  861. Consider using the <b>sqlite_changes()</b> API function instead.</p></li>
  862. <li><p><b>PRAGMA default_cache_size;
  863. <br>PRAGMA default_cache_size = </b><i>Number-of-pages</i><b>;</b></p>
  864. <p>Query or change the maximum number of database disk pages that SQLite
  865. will hold in memory at once. Each page uses about 1.5K of memory.
  866. This pragma works like the <b>cache_size</b> pragma with the addition
  867. feature that it changes the cache size persistently. With this pragma,
  868. you can set the cache size once and that setting is retained and reused
  869. everytime you reopen the database.</p></li>
  870. <li><p><b>PRAGMA default_synchronous;
  871. <br>PRAGMA default_synchronous = ON;
  872. <br>PRAGMA default_synchronous = OFF;</b></p>
  873. <p>Query or change the setting of the "synchronous" flag in
  874. the database. When synchronous is on (the default), the SQLite database
  875. engine will pause at critical moments to make sure that data has actually
  876. be written to the disk surface. (In other words, it invokes the
  877. equivalent of the <b>fsync()</b> system call.) In synchronous mode,
  878. an SQLite database should be fully recoverable even if the operating
  879. system crashes or power is interrupted unexpectedly. The penalty for
  880. this assurance is that some database operations take longer because the
  881. engine has to wait on the (relatively slow) disk drive. The alternative
  882. is to turn synchronous off. With synchronous off, SQLite continues
  883. processing as soon as it has handed data off to the operating system.
  884. If the application running SQLite crashes, the data will be safe, but
  885. the database could (in theory) become corrupted if the operating system
  886. crashes or the computer suddenly loses power. On the other hand, some
  887. operations are as much as 50 or more times faster with synchronous off.
  888. </p>
  889. <p>This pragma changes the synchronous mode persistently. Once changed,
  890. the mode stays as set even if the database is closed and reopened. The
  891. <b>synchronous</b> pragma does the same thing but only applies the setting
  892. to the current session.</p>
  893. <li><p><b>PRAGMA empty_result_callbacks = ON;
  894. <br>PRAGMA empty_result_callbacks = OFF;</b></p>
  895. <p>When on, the EMPTY_RESULT_CALLBACKS pragma causes the callback
  896. function to be invoked once for each query that has an empty result
  897. set. The third "<b>argv</b>" parameter to the callback is set to NULL
  898. because there is no data to report. But the second "<b>argc</b>" and
  899. fourth "<b>columnNames</b>" parameters are valid and can be used to
  900. determine the number and names of the columns that would have been in
  901. the result set had the set not been empty.</p>
  902. <li><p><b>PRAGMA full_column_names = ON;
  903. <br>PRAGMA full_column_names = OFF;</b></p>
  904. <p>The column names reported in an SQLite callback are normally just
  905. the name of the column itself, except for joins when "TABLE.COLUMN"
  906. is used. But when full_column_names is turned on, column names are
  907. always reported as "TABLE.COLUMN" even for simple queries.</p></li>
  908. <li><p><b>PRAGMA index_info(</b><i>index-name</i><b>);</b></p>
  909. <p>For each column that the named index references, invoke the
  910. callback function
  911. once with information about that column, including the column name,
  912. and the column number.</p>
  913. <li><p><b>PRAGMA index_list(</b><i>table-name</i><b>);</b></p>
  914. <p>For each index on the named table, invoke the callback function
  915. once with information about that index. Arguments include the
  916. index name and a flag to indicate whether or not the index must be
  917. unique.</p>
  918. <li><p><b>PRAGMA parser_trace = ON;<br>PRAGMA parser_trace = OFF;</b></p>
  919. <p>Turn tracing of the SQL parser inside of the
  920. SQLite library on and off. This is used for debugging.
  921. This only works if the library is compiled without the NDEBUG macro.
  922. </p></li>
  923. <li><p><b>PRAGMA integrity_check;</b></p>
  924. <p>The command does an integrity check of the entire database. It
  925. looks for out-of-order records, missing pages, and malformed records.
  926. If any problems are found, then a single string is returned which is
  927. a description of all problems. If everything is in order, "ok" is
  928. returned.</p>
  929. <li><p><b>PRAGMA synchronous;
  930. <br>PRAGMA synchronous = ON;
  931. <br>PRAGMA synchronous = OFF;</b></p>
  932. <p>Query or change the setting of the "synchronous" flag in
  933. the database for the duration of the current database connect.
  934. The synchronous flag reverts to its default value when the database
  935. is closed and reopened. For additional information on the synchronous
  936. flag, see the description of the <b>default_synchronous</b> pragma.</p>
  937. </li>
  938. <li><p><b>PRAGMA table_info(</b><i>table-name</i><b>);</b></p>
  939. <p>For each column in the named table, invoke the callback function
  940. once with information about that column, including the column name,
  941. data type, whether or not the column can be NULL, and the default
  942. value for the column.</p>
  943. <li><p><b>PRAGMA vdbe_trace = ON;<br>PRAGMA vdbe_trace = OFF;</b></p>
  944. <p>Turn tracing of the virtual database engine inside of the
  945. SQLite library on and off. This is used for debugging.</p></li>
  946. </ul>
  947. <p>No error message is generated if an unknown pragma is issued.
  948. Unknown pragmas are ignored.</p>
  949. }
  950. Section REPLACE replace
  951. Syntax {sql-statement} {
  952. REPLACE INTO <table-name> [( <column-list> )] VALUES ( <value-list> ) |
  953. REPLACE INTO <table-name> [( <column-list> )] <select-statement>
  954. }
  955. puts {
  956. <p>The REPLACE command is an alias for the "INSERT OR REPLACE" variant
  957. of the <a href="#insert">INSERT command</a>. This alias is provided for
  958. compatibility with MySQL. See the
  959. <a href="#insert">INSERT command</a> documentation for additional
  960. information.</p>
  961. }
  962. Section SELECT select
  963. Syntax {sql-statement} {
  964. SELECT <result> [FROM <table-list>]
  965. [WHERE <expr>]
  966. [GROUP BY <expr-list>]
  967. [HAVING <expr>]
  968. [<compound-op> <select>]*
  969. [ORDER BY <sort-expr-list>]
  970. [LIMIT <integer> [OFFSET <integer>]]
  971. } {result} {
  972. <result-column> [, <result-column>]*
  973. } {result-column} {
  974. STAR | <table-name> . STAR | <expr> [ [AS] <string> ]
  975. } {table-list} {
  976. <table> [<join-op> <table> <join-args>]*
  977. } {table} {
  978. <table-name> [AS <alias>] |
  979. ( <select> ) [AS <alias>]
  980. } {join-op} {
  981. , | [NATURAL] [LEFT | RIGHT | FULL] [OUTER | INNER] JOIN
  982. } {join-args} {
  983. [ON <expr>] [USING ( <id-list> )]
  984. } {sort-expr-list} {
  985. <expr> [<sort-order>] [, <expr> [<sort-order>]]*
  986. } {sort-order} {
  987. ASC | DESC
  988. } {compound_op} {
  989. UNION | UNION ALL | INTERSECT | EXCEPT
  990. }
  991. puts {
  992. <p>The SELECT statement is used to query the database. The
  993. result of a SELECT is zero or more rows of data where each row
  994. has a fixed number of columns. The number of columns in the
  995. result is specified by the expression list in between the
  996. SELECT and FROM keywords. Any arbitrary expression can be used
  997. as a result. If a result expression is }
  998. puts "[Operator *] then all columns of all tables are substituted"
  999. puts {for that one expression.</p>
  1000. <p>The query is executed again one or more tables specified after
  1001. the FROM keyword. If multiple tables names are separated by commas,
  1002. then the query is against the cross join of the various tables.
  1003. The full SQL-92 join syntax can also be used to specify joins.
  1004. A sub-query
  1005. in parentheses may be substituted for any table name in the FROM clause.
  1006. The entire FROM clause may be omitted, in which case the result is a
  1007. single row consisting of the values of the expression list.
  1008. </p>
  1009. <p>The WHERE clause can be used to limit the number of rows over
  1010. which the query operates. In the current implementation,
  1011. indices will only be used to
  1012. optimize the query if WHERE expression contains equality comparisons
  1013. connected by the AND operator.</p>
  1014. <p>The GROUP BY clauses causes one or more rows of the result to
  1015. be combined into a single row of output. This is especially useful
  1016. when the result contains aggregate functions. The expressions in
  1017. the GROUP BY clause do <em>not</em> have to be expressions that
  1018. appear in the result. The HAVING clause is similar to WHERE except
  1019. that HAVING applies after grouping has occurred. The HAVING expression
  1020. may refer to values, even aggregate functions, that are not in the result.</p>
  1021. <p>The ORDER BY clause causes the output rows to be sorted.
  1022. The argument to ORDER BY is a list of expressions that are used as the
  1023. key for the sort. The expressions do not have to be part of the
  1024. result for a simple SELECT, but in a compound SELECT each sort
  1025. expression must exactly match one of the result columns. Each
  1026. sort expression may be optionally followed by ASC or DESC to specify
  1027. the sort order.</p>
  1028. <p>The LIMIT clause places an upper bound on the number of rows
  1029. returned in the result. A LIMIT of 0 indicates no upper bound.
  1030. The optional OFFSET following LIMIT specifies how many
  1031. rows to skip at the beginning of the result set.</p>
  1032. <p>A compound SELECT is formed from two or more simple SELECTs connected
  1033. by one of the operators UNION, UNION ALL, INTERSECT, or EXCEPT. In
  1034. a compound SELECT, all the constituent SELECTs must specify the
  1035. same number of result columns. There may be only a single ORDER BY
  1036. clause at the end of the compound SELECT. The UNION and UNION ALL
  1037. operators combine the results of the SELECTs to the right and left into
  1038. a single big table. The difference is that in UNION all result rows
  1039. are distinct where in UNION ALL there may be duplicates.
  1040. The INTERSECT operator takes the intersection of the results of the
  1041. left and right SELECTs. EXCEPT takes the result of left SELECT after
  1042. removing the results of the right SELECT. When three are more SELECTs
  1043. are connected into a compound, they group from left to right.</p>
  1044. }
  1045. Section UPDATE update
  1046. Syntax {sql-statement} {
  1047. UPDATE [ OR <conflict-algorithm> ] <table-name>
  1048. SET <assignment> [, <assignment>]
  1049. [WHERE <expr>]
  1050. } {assignment} {
  1051. <column-name> = <expr>
  1052. }
  1053. puts {
  1054. <p>The UPDATE statement is used to change the value of columns in
  1055. selected rows of a table. Each assignment in an UPDATE specifies
  1056. a column name to the left of the equals sign and an arbitrary expression
  1057. to the right. The expressions may use the values of other columns.
  1058. All expressions are evaluated before any assignments are made.
  1059. A WHERE clause can be used to restrict which rows are updated.</p>
  1060. <p>The optional conflict-clause allows the specification of an alternative
  1061. constraint conflict resolution algorithm to use during this one command.
  1062. See the section titled
  1063. <a href="#conflict">ON CONFLICT</a> for additional information.</p>
  1064. }
  1065. Section VACUUM vacuum
  1066. Syntax {sql-statement} {
  1067. VACUUM [<index-or-table-name>]
  1068. }
  1069. puts {
  1070. <p>The VACUUM command is an SQLite extension modelled after a similar
  1071. command found in PostgreSQL. If VACUUM is invoked with the name of a
  1072. table or index then it is suppose to clean up the named table or index.
  1073. In version 1.0 of SQLite, the VACUUM command would invoke
  1074. <b>gdbm_reorganize()</b> to clean up the backend database file.
  1075. Beginning with version 2.0 of SQLite, GDBM is no longer used for
  1076. the database backend and VACUUM has become a no-op.
  1077. </p>
  1078. }
  1079. puts {
  1080. <p><hr /></p>
  1081. <p><a href="index.html"><img src="/goback.jpg" border=0 />
  1082. Back to the SQLite Home Page</a>
  1083. </p>
  1084. </body></html>}