Update documentation to better explain the typelessness of SQLite and to
describe the distinction between text and numeric data. (CVS 711) FossilOrigin-Name: 4ff0f578eca4a8672cf570923e6c015c3ba6b9f4
This commit is contained in:
parent
a9e99aee95
commit
fbe4375cae
6
main.mk
6
main.mk
@ -299,6 +299,9 @@ download.html: $(TOP)/www/download.tcl
|
||||
omitted.html: $(TOP)/www/omitted.tcl
|
||||
tclsh $(TOP)/www/omitted.tcl >omitted.html
|
||||
|
||||
datatypes.html: $(TOP)/www/datatypes.tcl
|
||||
tclsh $(TOP)/www/datatypes.tcl >datatypes.html
|
||||
|
||||
|
||||
# Files to be published on the website.
|
||||
#
|
||||
@ -320,7 +323,8 @@ DOC = \
|
||||
faq.html \
|
||||
formatchng.html \
|
||||
conflict.html \
|
||||
omitted.html
|
||||
omitted.html \
|
||||
datatypes.html
|
||||
|
||||
doc: $(DOC)
|
||||
mkdir -p doc
|
||||
|
18
manifest
18
manifest
@ -1,5 +1,5 @@
|
||||
C Make\sthe\sdistinction\sbetween\stext\sand\snumeric\sdata.\s(CVS\s710)
|
||||
D 2002-08-13T23:02:57
|
||||
C Update\sdocumentation\sto\sbetter\sexplain\sthe\stypelessness\sof\sSQLite\sand\sto\ndescribe\sthe\sdistinction\sbetween\stext\sand\snumeric\sdata.\s(CVS\s711)
|
||||
D 2002-08-14T00:08:13
|
||||
F Makefile.in 6291a33b87d2a395aafd7646ee1ed562c6f2c28c
|
||||
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
|
||||
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
|
||||
@ -14,7 +14,7 @@ F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac
|
||||
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
|
||||
F libtool c56e618713c9510a103bda6b95f3ea3900dcacd6
|
||||
F ltmain.sh e9ed72eb1d690f447c13945eaf69e28af531eda1
|
||||
F main.mk 34e976d914ac76ba90a93d2b7c41c1a7498e8c59
|
||||
F main.mk 6f0f1cfd611e5ead3e7487b0e8b60ccb17d9fc0b
|
||||
F publish.sh a7a8d23e6525bd25d4f5ba9b0fc6edc107d94050
|
||||
F spec.template 238f7db425a78dc1bb7682e56e3834c7270a3f5e
|
||||
F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea
|
||||
@ -131,19 +131,21 @@ F www/c_interface.tcl fb87b825b9032b9aa941694c5c9c5aee9424467e
|
||||
F www/changes.tcl df6f06b1aa97ef285c744bf19ec3efddf707b05f
|
||||
F www/conflict.tcl 81dd21f9a679e60aae049e9dd8ab53d59570cda2
|
||||
F www/crosscompile.tcl 3622ebbe518927a3854a12de51344673eb2dd060
|
||||
F www/datatypes.tcl c18a57dd02ba12bbede52f24ae9325f7fc1bf463
|
||||
F www/download.tcl 29aa6679ca29621d10613f60ebbbda18f4b91c49
|
||||
F www/dynload.tcl 02eb8273aa78cfa9070dd4501dca937fb22b466c
|
||||
F www/faq.tcl e5a752ff431a8408ae24a91ab88ded2dfe699e16
|
||||
F www/formatchng.tcl b4449e065d2da38b6563bdf12cf46cfe1d4d765e
|
||||
F www/index.tcl 47945cc79706e9f2caf797330412c112d54ad72b
|
||||
F www/lang.tcl 8c3d0bda030f110c754b5edbad75eddf5dbe2ed1
|
||||
F www/index.tcl 9af69527a26895ec56ad920d4c51541c3e5643a6
|
||||
F www/lang.tcl 902f677258ee63dd8f6677b54118f354a1d824b6
|
||||
F www/mingw.tcl f1c7c0a7f53387dd9bb4f8c7e8571b7561510ebc
|
||||
F www/omitted.tcl 7a6d6598e6a6a09bf54a02e0aff0f29e407d9f11
|
||||
F www/opcode.tcl 33c5f2061a05c5d227c72b84c080b3bf74c74f8b
|
||||
F www/speed.tcl 7fc83f1b018e1ecc451838449542c3079ed12425
|
||||
F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
|
||||
F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
|
||||
F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
|
||||
P 92c403f485390bbd83a5be472e61c974f76d46b1
|
||||
R 4eff7fd5f3310391432b7a4cfb68c2be
|
||||
P 310ac4fbaf0ed63f98bfacb55259960be03b0c8b
|
||||
R 66d58d14066d17fd95f1b8c2d419e072
|
||||
U drh
|
||||
Z 8efada5c2bc32cebfca6eea0d127d8d7
|
||||
Z caee8504007932315996b27a5456db2c
|
||||
|
@ -1 +1 @@
|
||||
310ac4fbaf0ed63f98bfacb55259960be03b0c8b
|
||||
4ff0f578eca4a8672cf570923e6c015c3ba6b9f4
|
199
www/datatypes.tcl
Normal file
199
www/datatypes.tcl
Normal file
@ -0,0 +1,199 @@
|
||||
#
|
||||
# Run this script to generated a datatypes.html output file
|
||||
#
|
||||
set rcsid {$Id: datatypes.tcl,v 1.1 2002/08/14 00:08:13 drh Exp $}
|
||||
|
||||
puts {<html>
|
||||
<head>
|
||||
<title>Datatypes In SQLite</title>
|
||||
</head>
|
||||
<body bgcolor="white">
|
||||
<h1 align="center">
|
||||
Datatypes In SQLite
|
||||
</h1>
|
||||
}
|
||||
puts "<p align=center>
|
||||
(This page was last modified on [lrange $rcsid 3 4] UTC)
|
||||
</p>"
|
||||
|
||||
puts {<h2>1.0 Typelessness</h2>
|
||||
<p>
|
||||
SQLite is "typeless". This means that you can store any
|
||||
kind of data you want in any column of any table, regardless of the
|
||||
declared datatype of that column.
|
||||
(See the one exception to this rule in section 2.0 below.)
|
||||
This behavior is a feature, not
|
||||
a bug. A database is suppose to store and retrieve data and it
|
||||
should not matter to the database what format that data is in.
|
||||
The strong typing system found in most other SQL engines and
|
||||
codified in the SQL language spec is a misfeature -
|
||||
it is an example of the implementation showing through into the
|
||||
interface. SQLite seeks to overcome this misfeature by allowing
|
||||
you to store any kind of data into any kind of column and by
|
||||
allowing flexibility in the specification of datatypes.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
A datatype to SQLite is any sequence of zero or more names
|
||||
optionally followed by a parenthesized lists of one or two
|
||||
signed integers. Notice in particular that a datatype may
|
||||
be <em>zero</em> or more names. That means that an empty
|
||||
string is a valid datatype as far as SQLite is concerned.
|
||||
So you can declare tables where the datatype of each column
|
||||
is left unspecified, like this:
|
||||
</p>
|
||||
|
||||
<blockquote><pre>
|
||||
CREATE TABLE ex1(a,b,c);
|
||||
</pre></blockquote>
|
||||
|
||||
<p>
|
||||
Even though SQLite allows the datatype to be omitted, it is
|
||||
still a good idea to include it in your CREATE TABLE statements,
|
||||
since the data type often serves as a good hint to other
|
||||
programmers about what you intend to put in the column. And
|
||||
if you ever port your code to another database engine, that
|
||||
other engine will probably require a datatype of some kind.
|
||||
SQLite accepts all the usual datatypes. For example:
|
||||
</p>
|
||||
|
||||
<blockquote><pre>
|
||||
CREATE TABLE ex2(
|
||||
a VARCHAR(10),
|
||||
b NVARCHAR(15),
|
||||
c TEXT,
|
||||
d INTEGER,
|
||||
e FLOAT,
|
||||
f BOOLEAN,
|
||||
g CLOB,
|
||||
h BLOB,
|
||||
i TIMESTAMP,
|
||||
j NUMERIC(10,5)
|
||||
k VARYING CHARACTER (24),
|
||||
l NATIVE VARYING CHAR(16)
|
||||
);
|
||||
</pre></blockquote>
|
||||
|
||||
<p>
|
||||
And so forth. Basically any sequence of names optionally followed by
|
||||
one or two signed integers in parentheses will do.
|
||||
</p>
|
||||
|
||||
<h2>2.0 The INTEGER PRIMARY KEY</h2>
|
||||
|
||||
<p>
|
||||
One exception to the typelessness of SQLite is a column whose type
|
||||
is INTEGER PRIMARY KEY. (And you must use "INTEGER" not "INT".
|
||||
A column of type INT PRIMARY KEY is typeless just like any other.)
|
||||
INTEGER PRIMARY KEY columns must contain a 32-bit signed integer. Any
|
||||
attempt to insert non-integer data will result in an error.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
INTEGER PRIMARY KEY columns can be used to implement the equivalent
|
||||
of AUTOINCREMENT. If you try to insert a NULL into an INTEGER PRIMARY
|
||||
KEY column, the column will actually be filled with a integer that is
|
||||
one greater than the largest key already in the table. Or if the
|
||||
largest key is 2147483647, then the column will be filled with a
|
||||
random integer. Either way, the INTEGER PRIMARY KEY column will be
|
||||
assigned a unique integer. You can retrieve this integer using
|
||||
the <b>sqlite_last_insert_rowid()</b> API function or using the
|
||||
<b>last_insert_rowid()</b> SQL function is a subsequent SELECT statement.
|
||||
</p>
|
||||
|
||||
<h2>3.0 Comparison and Sort Order</h2>
|
||||
|
||||
<p>
|
||||
SQLite is typeless for the purpose of deciding what data is allowed
|
||||
to be stored in a column. But some notion of type comes into play
|
||||
when sorting and comparing data. For these purposes, a column or
|
||||
an expression can be one of two types: <b>numeric</b> and <b>text</b>.
|
||||
The sort or comparison may give different results depending on which
|
||||
type of data is being sorted or compared.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
If data is of type <b>text</b> then the comparison is determined by
|
||||
the standard C data comparison functions <b>memcmp()</b> or
|
||||
<b>strcmp()</b>. The comparison looks at bytes from two inputs one
|
||||
by one and returns the first non-zero difference.
|
||||
String are '\000' terminated so shorter
|
||||
strings sort before longer strings, as you would expect.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
For numeric data, this situation is more complex. If both strings
|
||||
being compared look like well-formed numbers, then they are converted
|
||||
into floating point values using <b>atof()</b> and compared numerically.
|
||||
If one input is not a well-formed number but the other is, then the
|
||||
number is considered to be less than the non-number. If neither inputs
|
||||
is a well-formed number, then <b>strcmp()</b> is used to do the
|
||||
comparison.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Do not be confused by the fact that a column might have a "numeric"
|
||||
datatype. This does not mean that the column can contain only numbers.
|
||||
It merely means that if the column does contain a number, that number
|
||||
will sort in numerical order.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
For both text and numeric values, NULL sorts before any other value.
|
||||
A comparison of any value against NULL using operators like "<" or
|
||||
">=" is always false.
|
||||
</p>
|
||||
|
||||
<h2>4.0 How SQLite Determines Datatypes</h2>
|
||||
|
||||
<p>
|
||||
For SQLite version 2.6.3 and earlier, all values used the numeric datatype.
|
||||
The text datatype appears in version 2.7.0 and later. In the sequel it
|
||||
is assumed that you are using version 2.7.0 or later of SQLite.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
For an expression, the datatype of the result is often determined by
|
||||
the outermost operator. For example, arithmatic operators ("+", "*", "%")
|
||||
always return a numeric results. The string concatenation operator
|
||||
("||") returns a text result. And so forth. If you are ever in doubt
|
||||
about the datatype of an expression you can use the special <b>typeof()</b>
|
||||
SQL function to determine what the datatype is. For example:
|
||||
</p>
|
||||
|
||||
<blockquote><pre>
|
||||
sqlite> SELECT typeof('abc'+123);
|
||||
numeric
|
||||
sqlite> SELECT typeof('abc'||123);
|
||||
text
|
||||
</pre></blockquote>
|
||||
|
||||
<p>
|
||||
For table columns, the datatype is determined by the datatype declaration
|
||||
of the CREATE TABLE statement. The datatype is text if and only if
|
||||
the type declaration contains one or more of the following strings:
|
||||
</p>
|
||||
|
||||
<blockquote>
|
||||
BLOB<br>
|
||||
CHAR<br>
|
||||
CLOB</br>
|
||||
TEXT
|
||||
</blockquote>
|
||||
|
||||
<p>
|
||||
The search for these strings in the type declaration is case insensitive,
|
||||
of course. If any of the above strings occur anywhere in the type
|
||||
declaration, then the datatype of the column is text. Otherwise the
|
||||
datatype is numeric. Note in particular that the datatype for columns
|
||||
with an empty type declaration is numeric.
|
||||
</p>
|
||||
}
|
||||
|
||||
puts {
|
||||
<p><hr /></p>
|
||||
<p><a href="index.html"><img src="/goback.jpg" border=0 />
|
||||
Back to the SQLite Home Page</a>
|
||||
</p>
|
||||
|
||||
</body></html>}
|
@ -1,7 +1,7 @@
|
||||
#
|
||||
# Run this TCL script to generate HTML for the index.html file.
|
||||
#
|
||||
set rcsid {$Id: index.tcl,v 1.64 2002/08/13 20:45:41 drh Exp $}
|
||||
set rcsid {$Id: index.tcl,v 1.65 2002/08/14 00:08:13 drh Exp $}
|
||||
|
||||
puts {<html>
|
||||
<head><title>SQLite: An SQL Database Engine In A C Library</title></head>
|
||||
@ -132,6 +132,7 @@ puts {<h2>Documentation</h2>
|
||||
<li><a href="faq.html">Frequently Asked Questions</a> are available online.</li>
|
||||
<li>Information on the <a href="sqlite.html">sqlite</a>
|
||||
command-line utility.</li>
|
||||
<li>SQLite is <a href="datatypes.html">typeless</a>.
|
||||
<li>The <a href="lang.html">SQL Language</a> subset understood by SQLite.</li>
|
||||
<li>The <a href="c_interface.html">C/C++ Interface</a>.</li>
|
||||
<li>The <a href="tclsqlite.html">Tcl Binding</a> to SQLite.</li>
|
||||
|
@ -1,7 +1,7 @@
|
||||
#
|
||||
# Run this Tcl script to generate the sqlite.html file.
|
||||
#
|
||||
set rcsid {$Id: lang.tcl,v 1.41 2002/06/25 01:09:13 drh Exp $}
|
||||
set rcsid {$Id: lang.tcl,v 1.42 2002/08/14 00:08:13 drh Exp $}
|
||||
|
||||
puts {<html>
|
||||
<head>
|
||||
@ -282,7 +282,9 @@ for use by the engine.</p>
|
||||
|
||||
<p>Each column definition is the name of the column followed by the
|
||||
datatype for that column, then one or more optional column constraints.
|
||||
The datatype for the column is (usually) ignored and may be omitted.
|
||||
SQLite is <a href="datatypes.html">typeless</a>.
|
||||
The datatype for the column does not constraint what data may be put
|
||||
in that column.
|
||||
All information is stored as null-terminated strings.
|
||||
The UNIQUE constraint causes an index to be created on the specified
|
||||
columns. This index must contain unique keys.
|
||||
|
91
www/omitted.tcl
Normal file
91
www/omitted.tcl
Normal file
@ -0,0 +1,91 @@
|
||||
#
|
||||
# Run this script to generated a omitted.html output file
|
||||
#
|
||||
set rcsid {$Id: omitted.tcl,v 1.1 2002/08/14 00:08:14 drh Exp $}
|
||||
|
||||
puts {<html>
|
||||
<head>
|
||||
<title>SQL Features That SQLite Does Not Implement</title>
|
||||
</head>
|
||||
<body bgcolor="white">
|
||||
<h1 align="center">
|
||||
SQL Features That SQLite Does Not Implement
|
||||
</h1>
|
||||
}
|
||||
puts "<p align=center>
|
||||
(This page was last modified on [lrange $rcsid 3 4] UTC)
|
||||
</p>"
|
||||
|
||||
puts {
|
||||
<p>
|
||||
Rather than try to list all the features of SQL92 that SQLite does
|
||||
support, it is much easier to list those that it does not.
|
||||
The following are features of of SQL92 that SQLite does not implement.
|
||||
</p>
|
||||
|
||||
<table cellpadding="10">
|
||||
}
|
||||
|
||||
proc feature {name desc} {
|
||||
puts "<tr><td valign=\"top\"><b><nobr>$name</nobr></b></td>"
|
||||
puts "<td valign=\"top\">$desc</td></tr>"
|
||||
}
|
||||
|
||||
feature {RIGHT and FULL OUTER JOIN} {
|
||||
LEFT OUTER JOIN is implemented, but not RIGHT OUTER JOIN or
|
||||
FULL OUTER JOIN.
|
||||
}
|
||||
|
||||
feature {CHECK constraints} {
|
||||
CHECK constraints are parsed but they are not enforced.
|
||||
NOT NULL and UNIQUE constraints are enforced, however.
|
||||
}
|
||||
|
||||
feature {FOREIGN KEY constraints} {
|
||||
FOREIGN KEY constraints are parsed but are ignored.
|
||||
}
|
||||
|
||||
feature {GRANT and REVOKE} {
|
||||
Since SQLite reads and writes an ordinary disk file, the
|
||||
only access permissions that can be applied are the normal
|
||||
file access permissions of the underlying operating system.
|
||||
The GRANT and REVOKE commands commonly found on client/server
|
||||
RDBMSes are not implemented because they would be meaningless
|
||||
for an embedded database engine.
|
||||
}
|
||||
|
||||
feature {DELETE, INSERT, and UPDATE on VIEWs} {
|
||||
VIEWs in SQLite are read-only. But you can create a trigger
|
||||
that fires on an attempt to DELETE, INSERT, or UPDATE a view and do
|
||||
what you need in the body of the trigger.
|
||||
}
|
||||
|
||||
feature {ALTER TABLE} {
|
||||
To change a table you have to delete it (saving its contents to a temporary
|
||||
table) and recreate it from scratch.
|
||||
}
|
||||
|
||||
feature {The COUNT(DISTINCT X) function} {
|
||||
You can accomplish the same thing using a subquery, like this:<br />
|
||||
SELECT count(x) FROM (SELECT DISTINCT x FROM tbl);
|
||||
}
|
||||
|
||||
feature {Variable subqueries} {
|
||||
Subqueries must be static. They are evaluated only once. They must not,
|
||||
therefore, refer to variables in the containing query.
|
||||
}
|
||||
|
||||
puts {
|
||||
</table>
|
||||
|
||||
<p>
|
||||
If you find other SQL92 features that SQLite does not support, please
|
||||
send e-mail to <a href="mailto:drh@hwaci.com">drh@hwaci.com</a> so they
|
||||
can be added to this list.
|
||||
</p>
|
||||
<p><hr /></p>
|
||||
<p><a href="index.html"><img src="/goback.jpg" border=0 />
|
||||
Back to the SQLite Home Page</a>
|
||||
</p>
|
||||
|
||||
</body></html>}
|
Loading…
x
Reference in New Issue
Block a user