|
1 |
| -## Work in progress |
2 |
| -You may ask questions in the chat window below or |
3 |
| -refer to [legacy documentation](https://docs.datajoint.org/) |
| 1 | +# Datatypes |
| 2 | + |
| 3 | +DataJoint supports the following datatypes. |
| 4 | +To conserve database resources, use the smallest and most restrictive datatype |
| 5 | +sufficient for your data. |
| 6 | +This also ensures that only valid data are entered into the pipeline. |
| 7 | + |
| 8 | +## Most common datatypes |
| 9 | + |
| 10 | +- `tinyint`: an 8-bit integer number, ranging from -128 to 127. |
| 11 | +- `tinyint unsigned`: an 8-bit positive integer number, ranging from 0 to 255. |
| 12 | +- `smallint`: a 16-bit integer number, ranging from -32,768 to 32,767. |
| 13 | +- `smallint unsigned`: a 16-bit positive integer, ranging from 0 to 65,535. |
| 14 | +- `int`: a 32-bit integer number, ranging from -2,147,483,648 to 2,147,483,647. |
| 15 | +- `int unsigned`: a 32-bit positive integer, ranging from 0 to 4,294,967,295. |
| 16 | +- `enum`: one of several explicitly enumerated values specified as strings. |
| 17 | + Use this datatype instead of text strings to avoid spelling variations and to save |
| 18 | + storage space. |
| 19 | + For example, the datatype for an anesthesia attribute could be |
| 20 | + `enum("urethane", "isoflurane", "fentanyl")`. |
| 21 | + Do not use enums in primary keys due to the difficulty of changing their definitions |
| 22 | + consistently in multiple tables. |
| 23 | + |
| 24 | +- `date`: date as `'YYYY-MM-DD'`. |
| 25 | +- `time`: time as `'HH:MM:SS'`. |
| 26 | +- `datetime`: Date and time to the second as `'YYYY-MM-DD HH:MM:SS'` |
| 27 | +- `timestamp`: Date and time to the second as `'YYYY-MM-DD HH:MM:SS'`. |
| 28 | + The default value may be set to `CURRENT_TIMESTAMP`. |
| 29 | + Unlike `datetime`, a `timestamp` value will be adjusted to the local time zone. |
| 30 | + |
| 31 | +- `char(N)`: a character string up to *N* characters (but always takes the entire *N* |
| 32 | +bytes to store). |
| 33 | +- `varchar(N)`: a text string of arbitrary length up to *N* characters that takes |
| 34 | +*M+1* or *M+2* bytes of storage, where *M* is the actual length of each stored string. |
| 35 | +- `float`: a single-precision floating-point number. |
| 36 | + Takes 4 bytes. |
| 37 | + Single precision is sufficient for many measurements. |
| 38 | + |
| 39 | +- `double`: a double-precision floating-point number. |
| 40 | + Takes 8 bytes. |
| 41 | + Because equality comparisons are error-prone, neither `float` nor `double` should be |
| 42 | + used in primary keys. |
| 43 | +- `decimal(N,F)`: a fixed-point number with *N* total decimal digits and *F* |
| 44 | +fractional digits. |
| 45 | + This datatype is well suited to represent numbers whose magnitude is well defined |
| 46 | + and does not warrant the use of floating-point representation or requires precise |
| 47 | + decimal representations (e.g. dollars and cents). |
| 48 | + Because of its well-defined precision, `decimal` values can be used in equality |
| 49 | + comparison and be included in primary keys. |
| 50 | + |
| 51 | +- `longblob`: arbitrary numeric array (e.g. matrix, image, structure), up to 4 |
| 52 | +[GiB](http://en.wikipedia.org/wiki/Gibibyte) in size. |
| 53 | + Numeric arrays are compatible between MATLAB and Python (NumPy). |
| 54 | + The `longblob` and other `blob` datatypes can be configured to store data |
| 55 | + [externally](../../sysadmin/external-store.md) by using the `blob@store` syntax. |
| 56 | + |
| 57 | +## Less common (but supported) datatypes |
| 58 | + |
| 59 | +- `decimal(N,F) unsigned`: same as `decimal`, but limited to nonnegative values. |
| 60 | +- `mediumint` a 24-bit integer number, ranging from -8,388,608 to 8,388,607. |
| 61 | +- `mediumint unsigned`: a 24-bit positive integer, ranging from 0 to 16,777,216. |
| 62 | +- `mediumblob`: arbitrary numeric array, up to 16 |
| 63 | +[MiB](http://en.wikipedia.org/wiki/Mibibyte) |
| 64 | +- `blob`: arbitrary numeric array, up to 64 |
| 65 | +[KiB](http://en.wikipedia.org/wiki/Kibibyte) |
| 66 | +- `tinyblob`: arbitrary numeric array, up to 256 bytes (actually smaller due to header |
| 67 | +info). |
| 68 | + |
| 69 | +## Special DataJoint-only datatypes |
| 70 | + |
| 71 | +These types abstract certain kinds of non-database data to facilitate use |
| 72 | +together with DataJoint. |
| 73 | + |
| 74 | +- `attach`: a [file attachment](attach.md) similar to email attachments facillitating |
| 75 | +sending/receiving an opaque data file to/from a DataJoint pipeline. |
| 76 | + |
| 77 | +- `filepath@store`: a [filepath](filepath.md) used to link non-DataJoint managed files |
| 78 | +into a DataJoint pipeline. |
| 79 | + |
| 80 | +## Datatypes not (yet) supported |
| 81 | + |
| 82 | +- `binary` |
| 83 | +- `text` |
| 84 | +- `longtext` |
| 85 | +- `bit` |
| 86 | + |
| 87 | +For additional information about these datatypes, see |
| 88 | +http://dev.mysql.com/doc/refman/5.6/en/data-types.html |
0 commit comments