303 lines
14 KiB
HTML
303 lines
14 KiB
HTML
<!DOCTYPE html>
|
|
<html><head>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
<link href="sqlite.css" rel="stylesheet">
|
|
<title>INSERT</title>
|
|
<!-- path= -->
|
|
</head>
|
|
<body>
|
|
<div class=nosearch>
|
|
<a href="index.html">
|
|
<img class="logo" src="images/sqlite370_banner.gif" alt="SQLite" border="0">
|
|
</a>
|
|
<div><!-- IE hack to prevent disappearing logo --></div>
|
|
<div class="tagline desktoponly">
|
|
Small. Fast. Reliable.<br>Choose any three.
|
|
</div>
|
|
<div class="menu mainmenu">
|
|
<ul>
|
|
<li><a href="index.html">Home</a>
|
|
<li class='mobileonly'><a href="javascript:void(0)" onclick='toggle_div("submenu")'>Menu</a>
|
|
<li class='wideonly'><a href='about.html'>About</a>
|
|
<li class='desktoponly'><a href="docs.html">Documentation</a>
|
|
<li class='desktoponly'><a href="download.html">Download</a>
|
|
<li class='wideonly'><a href='copyright.html'>License</a>
|
|
<li class='desktoponly'><a href="support.html">Support</a>
|
|
<li class='desktoponly'><a href="prosupport.html">Purchase</a>
|
|
<li class='search' id='search_menubutton'>
|
|
<a href="javascript:void(0)" onclick='toggle_search()'>Search</a>
|
|
</ul>
|
|
</div>
|
|
<div class="menu submenu" id="submenu">
|
|
<ul>
|
|
<li><a href='about.html'>About</a>
|
|
<li><a href='docs.html'>Documentation</a>
|
|
<li><a href='download.html'>Download</a>
|
|
<li><a href='support.html'>Support</a>
|
|
<li><a href='prosupport.html'>Purchase</a>
|
|
</ul>
|
|
</div>
|
|
<div class="searchmenu" id="searchmenu">
|
|
<form method="GET" action="search">
|
|
<select name="s" id="searchtype">
|
|
<option value="d">Search Documentation</option>
|
|
<option value="c">Search Changelog</option>
|
|
</select>
|
|
<input type="text" name="q" id="searchbox" value="">
|
|
<input type="submit" value="Go">
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
function toggle_div(nm) {
|
|
var w = document.getElementById(nm);
|
|
if( w.style.display=="block" ){
|
|
w.style.display = "none";
|
|
}else{
|
|
w.style.display = "block";
|
|
}
|
|
}
|
|
function toggle_search() {
|
|
var w = document.getElementById("searchmenu");
|
|
if( w.style.display=="block" ){
|
|
w.style.display = "none";
|
|
} else {
|
|
w.style.display = "block";
|
|
setTimeout(function(){
|
|
document.getElementById("searchbox").focus()
|
|
}, 30);
|
|
}
|
|
}
|
|
function div_off(nm){document.getElementById(nm).style.display="none";}
|
|
window.onbeforeunload = function(e){div_off("submenu");}
|
|
/* Disable the Search feature if we are not operating from CGI, since */
|
|
/* Search is accomplished using CGI and will not work without it. */
|
|
if( !location.origin || !location.origin.match || !location.origin.match(/http/) ){
|
|
document.getElementById("search_menubutton").style.display = "none";
|
|
}
|
|
/* Used by the Hide/Show button beside syntax diagrams, to toggle the */
|
|
function hideorshow(btn,obj){
|
|
var x = document.getElementById(obj);
|
|
var b = document.getElementById(btn);
|
|
if( x.style.display!='none' ){
|
|
x.style.display = 'none';
|
|
b.innerHTML='show';
|
|
}else{
|
|
x.style.display = '';
|
|
b.innerHTML='hide';
|
|
}
|
|
return false;
|
|
}
|
|
</script>
|
|
</div>
|
|
<div class=fancy>
|
|
<div class=nosearch>
|
|
<div class="fancy_title">
|
|
INSERT
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<p><b><a href="syntax/insert-stmt.html">insert-stmt:</a></b>
|
|
<button id='x1693' onclick='hideorshow("x1693","x1694")'>hide</button></p>
|
|
<div id='x1694' class='imgcontainer'>
|
|
<img alt="syntax diagram insert-stmt" src="images/syntax/insert-stmt.gif" />
|
|
<p><b><a href="syntax/common-table-expression.html">common-table-expression:</a></b>
|
|
<button id='x1695' onclick='hideorshow("x1695","x1696")'>show</button></p>
|
|
<div id='x1696' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram common-table-expression" src="images/syntax/common-table-expression.gif" />
|
|
</div>
|
|
<p><b><a href="syntax/expr.html">expr:</a></b>
|
|
<button id='x1697' onclick='hideorshow("x1697","x1698")'>show</button></p>
|
|
<div id='x1698' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram expr" src="images/syntax/expr.gif" />
|
|
<p><b><a href="syntax/filter-clause.html">filter-clause:</a></b>
|
|
<button id='x1699' onclick='hideorshow("x1699","x1700")'>show</button></p>
|
|
<div id='x1700' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram filter-clause" src="images/syntax/filter-clause.gif" />
|
|
</div>
|
|
<p><b><a href="syntax/literal-value.html">literal-value:</a></b>
|
|
<button id='x1701' onclick='hideorshow("x1701","x1702")'>show</button></p>
|
|
<div id='x1702' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram literal-value" src="images/syntax/literal-value.gif" />
|
|
</div>
|
|
<p><b><a href="syntax/over-clause.html">over-clause:</a></b>
|
|
<button id='x1703' onclick='hideorshow("x1703","x1704")'>show</button></p>
|
|
<div id='x1704' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram over-clause" src="images/syntax/over-clause.gif" />
|
|
<p><b><a href="syntax/frame-spec.html">frame-spec:</a></b>
|
|
<button id='x1705' onclick='hideorshow("x1705","x1706")'>show</button></p>
|
|
<div id='x1706' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram frame-spec" src="images/syntax/frame-spec.gif" />
|
|
</div>
|
|
<p><b><a href="syntax/ordering-term.html">ordering-term:</a></b>
|
|
<button id='x1707' onclick='hideorshow("x1707","x1708")'>show</button></p>
|
|
<div id='x1708' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram ordering-term" src="images/syntax/ordering-term.gif" />
|
|
</div>
|
|
</div>
|
|
<p><b><a href="syntax/raise-function.html">raise-function:</a></b>
|
|
<button id='x1709' onclick='hideorshow("x1709","x1710")'>show</button></p>
|
|
<div id='x1710' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram raise-function" src="images/syntax/raise-function.gif" />
|
|
</div>
|
|
<p><b><a href="syntax/type-name.html">type-name:</a></b>
|
|
<button id='x1711' onclick='hideorshow("x1711","x1712")'>show</button></p>
|
|
<div id='x1712' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram type-name" src="images/syntax/type-name.gif" />
|
|
<p><b><a href="syntax/signed-number.html">signed-number:</a></b>
|
|
<button id='x1713' onclick='hideorshow("x1713","x1714")'>show</button></p>
|
|
<div id='x1714' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram signed-number" src="images/syntax/signed-number.gif" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<p><b><a href="syntax/select-stmt.html">select-stmt:</a></b>
|
|
<button id='x1715' onclick='hideorshow("x1715","x1716")'>show</button></p>
|
|
<div id='x1716' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram select-stmt" src="images/syntax/select-stmt.gif" />
|
|
<p><b><a href="syntax/compound-operator.html">compound-operator:</a></b>
|
|
<button id='x1717' onclick='hideorshow("x1717","x1718")'>show</button></p>
|
|
<div id='x1718' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram compound-operator" src="images/syntax/compound-operator.gif" />
|
|
</div>
|
|
<p><b><a href="syntax/join-clause.html">join-clause:</a></b>
|
|
<button id='x1719' onclick='hideorshow("x1719","x1720")'>show</button></p>
|
|
<div id='x1720' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram join-clause" src="images/syntax/join-clause.gif" />
|
|
<p><b><a href="syntax/join-constraint.html">join-constraint:</a></b>
|
|
<button id='x1721' onclick='hideorshow("x1721","x1722")'>show</button></p>
|
|
<div id='x1722' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram join-constraint" src="images/syntax/join-constraint.gif" />
|
|
</div>
|
|
<p><b><a href="syntax/join-operator.html">join-operator:</a></b>
|
|
<button id='x1723' onclick='hideorshow("x1723","x1724")'>show</button></p>
|
|
<div id='x1724' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram join-operator" src="images/syntax/join-operator.gif" />
|
|
</div>
|
|
</div>
|
|
<p><b><a href="syntax/ordering-term.html">ordering-term:</a></b>
|
|
<button id='x1725' onclick='hideorshow("x1725","x1726")'>show</button></p>
|
|
<div id='x1726' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram ordering-term" src="images/syntax/ordering-term.gif" />
|
|
</div>
|
|
<p><b><a href="syntax/result-column.html">result-column:</a></b>
|
|
<button id='x1727' onclick='hideorshow("x1727","x1728")'>show</button></p>
|
|
<div id='x1728' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram result-column" src="images/syntax/result-column.gif" />
|
|
</div>
|
|
<p><b><a href="syntax/table-or-subquery.html">table-or-subquery:</a></b>
|
|
<button id='x1729' onclick='hideorshow("x1729","x1730")'>show</button></p>
|
|
<div id='x1730' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram table-or-subquery" src="images/syntax/table-or-subquery.gif" />
|
|
</div>
|
|
<p><b><a href="syntax/window-defn.html">window-defn:</a></b>
|
|
<button id='x1731' onclick='hideorshow("x1731","x1732")'>show</button></p>
|
|
<div id='x1732' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram window-defn" src="images/syntax/window-defn.gif" />
|
|
<p><b><a href="syntax/frame-spec.html">frame-spec:</a></b>
|
|
<button id='x1733' onclick='hideorshow("x1733","x1734")'>show</button></p>
|
|
<div id='x1734' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram frame-spec" src="images/syntax/frame-spec.gif" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<p><b><a href="syntax/upsert-clause.html">upsert-clause:</a></b>
|
|
<button id='x1735' onclick='hideorshow("x1735","x1736")'>show</button></p>
|
|
<div id='x1736' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram upsert-clause" src="images/syntax/upsert-clause.gif" />
|
|
<p><b><a href="syntax/column-name-list.html">column-name-list:</a></b>
|
|
<button id='x1737' onclick='hideorshow("x1737","x1738")'>show</button></p>
|
|
<div id='x1738' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram column-name-list" src="images/syntax/column-name-list.gif" />
|
|
</div>
|
|
<p><b><a href="syntax/indexed-column.html">indexed-column:</a></b>
|
|
<button id='x1739' onclick='hideorshow("x1739","x1740")'>show</button></p>
|
|
<div id='x1740' style='display:none;' class='imgcontainer'>
|
|
<img alt="syntax diagram indexed-column" src="images/syntax/indexed-column.gif" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<p>The INSERT statement comes in three basic forms.
|
|
</p><ol>
|
|
<li><p><b>INSERT INTO </b><i>table</i><b> VALUES(...);</b>
|
|
</p><p>The first form (with the "VALUES" keyword) creates one or more
|
|
new rows in
|
|
an existing table. If the <span class='yyterm'>column-name</span> list after
|
|
<span class='yyterm'>table-name</span> is omitted then the number
|
|
of values inserted into each row
|
|
must be the same as the number of columns in the table. In this case
|
|
the result of evaluating the left-most expression from each term of
|
|
the VALUES list is inserted into the left-most column of each new row,
|
|
and so forth for each subsequent expression. If a <span class='yyterm'>column-name</span>
|
|
list is specified, then the number of values in each term of the
|
|
VALUE list must match the number of
|
|
specified columns. Each of the named columns of the new row is populated
|
|
with the results of evaluating the corresponding VALUES expression. Table
|
|
columns that do not appear in the column list are populated with the
|
|
<a href="lang_createtable.html#dfltval">default column value</a> (specified as part of the <a href="lang_createtable.html">CREATE TABLE</a> statement), or
|
|
with NULL if no <a href="lang_createtable.html#dfltval">default value</a> is specified.
|
|
|
|
</p></li><li><p><b>INSERT INTO </b><i>table</i><b> SELECT ...;</b>
|
|
</p><p>The second form of the INSERT statement contains a <a href="lang_select.html">SELECT</a> statement
|
|
instead of a VALUES clause. A new entry is inserted into the table for each
|
|
row of data returned by executing the SELECT statement. If a column-list is
|
|
specified, the number of columns in the result of the SELECT must be the same
|
|
as the number of items in the column-list. Otherwise, if no column-list is
|
|
specified, the number of columns in the result of the SELECT must be the same
|
|
as the number of columns in the table. Any SELECT statement, including
|
|
<a href="lang_select.html#compound">compound SELECTs</a> and SELECT statements with <a href="lang_select.html#orderby">ORDER BY</a> and/or <a href="lang_select.html#limitoffset">LIMIT</a> clauses,
|
|
may be used in an INSERT statement of this form.
|
|
|
|
</p><p>To avoid a parsing ambiguity, the SELECT statement should always
|
|
contain a WHERE clause, even if that clause is simply "WHERE true",
|
|
if the <a href="syntax/upsert-clause.html">upsert-clause</a> is present. Without the WHERE clause, the
|
|
parser does not know if the token "ON" is part of a join constraint
|
|
on the SELECT, or the beginning of the <a href="syntax/upsert-clause.html">upsert-clause</a>.
|
|
|
|
</p></li><li><p><b>INSERT INTO </b><i>table</i><b> DEFAULT VALUES;</b>
|
|
</p><p>The third form of an INSERT statement is with DEFAULT VALUES.
|
|
The INSERT ... DEFAULT VALUES statement inserts a single new row into the
|
|
named table. Each column of the new row is populated with its
|
|
<a href="lang_createtable.html#dfltval">default value</a>, or with a NULL if no default value is specified
|
|
as part of the column definition in the <a href="lang_createtable.html">CREATE TABLE</a> statement.
|
|
The <a href="syntax/upsert-clause.html">upsert-clause</a> is not supported after DEFAULT VALUES.
|
|
|
|
</p></li></ol>
|
|
|
|
<p>
|
|
The initial "INSERT" keyword can be replaced by
|
|
"REPLACE" or "INSERT OR <i>action</i>" to specify an alternative
|
|
constraint <a href="lang_conflict.html">conflict resolution algorithm</a> to use during
|
|
that one INSERT command.
|
|
For compatibility with MySQL, the parser allows the use of the
|
|
single keyword <a href="lang_replace.html">REPLACE</a> as an
|
|
alias for "INSERT OR REPLACE".
|
|
|
|
</p><p>The optional "<i>schema-name</i><b>.</b>" prefix on the
|
|
<span class='yyterm'>table-name</span>
|
|
is supported for top-level INSERT statements only. The table name must be
|
|
unqualified for INSERT statements that occur within <a href="lang_createtrigger.html">CREATE TRIGGER</a> statements.
|
|
Similarly, the "DEFAULT VALUES" form of the INSERT statement is supported for
|
|
top-level INSERT statements only and not for INSERT statements within
|
|
triggers.
|
|
</p><p>
|
|
|
|
</p><p>The optional "AS <span class='yyterm'>alias</span>" phrase provides an alternative
|
|
name for the table into which content is being inserted. The alias name
|
|
can be used within WHERE and SET clauses of the <a href="lang_upsert.html">UPSERT</a>. If there is no
|
|
<a href="syntax/upsert-clause.html">upsert-clause</a>, then the <span class='yyterm'>alias</span> is pointless, but also
|
|
harmless.
|
|
|
|
</p><p>See the separate <a href="lang_upsert.html">UPSERT</a> documentation for the additional trailing
|
|
syntax that can cause an INSERT to behave as an UPDATE if the INSERT would
|
|
otherwise violate a uniqueness constraint. The <a href="lang_upsert.html">upsert clause</a> is not
|
|
allowed on an "INSERT ... DEFAULT VALUES".
|
|
</p>
|