Schema
Columns
Each field is a data type. The builder name is that type.
Each field is a data type. The builder name is that type. Postgres is the only database today. A cell is yes when that database has the type built in, and extension when the schema must list that extension. Another database is another column on the same row. A missing extension declaration is OKM1020. See extensions.
An array is .array() on a scalar. A fixed set of strings on a text column is a picklist. A named Postgres enum is its own type, under enum.
| You store | Builder | Type family |
|---|---|---|
| a string with no length cap | t.text() | Text |
| a string with a maximum length | t.varchar(n) | Text |
| a string compared without case | t.citext() | Text |
| a tight integer | t.smallint() | Integers |
| a typical count | t.integer() | Integers |
| a 64-bit integer | t.bigint() | Integers |
| a generated integer key | t.integerIdentity() | Integers |
| a generated 64-bit key | t.identity() | Integers |
| money, a rate, or any exact quantity | t.numeric(precision, scale) | Numbers |
| a measurement that may round | t.double() | Floats |
| an instant | t.timestamptz() | Time |
| a calendar day | t.date() | Time |
| a span | t.interval() | Time |
| true or false | t.boolean() | Boolean and binary |
| bytes | t.bytea() | Boolean and binary |
| a document you query | t.jsonb() | JSON |
| a uuid that is not the primary key | t.uuid() | UUID |
| a primary key the application mints | t.id({ default: okid() }) | OKID |
| a closed set of labels | t.enum(name, values) | Named types |
| Family | You use it for |
|---|---|
| Text | Text. |
| Numbers | Integers, numbers, and floats. |
| Date and time | Time. |
| Binary and JSON | Boolean, bytes, JSON, UUID, and OKID. |
| Postgres types | Ranges, network, geometry, search, named types, and other Postgres types. |