Skip to content

Commit 7d0a5a5

Browse files
Clarify nullability and default value handling
DataJoint handles nullability through the default value syntax: - Attribute is nullable iff default is NULL - No separate NOT NULL / NULL modifier needed - Examples: required, nullable, and default value cases Co-authored-by: dimitri-yatsenko <[email protected]>
1 parent 92647f1 commit 7d0a5a5

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

docs/src/design/tables/storage-types-spec.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ declarative syntax:
135135

136136
| Modifier | Status | DataJoint Alternative |
137137
|----------|--------|----------------------|
138-
| `NOT NULL` / `NULL` | ❌ Not allowed | Position above/below `---` determines nullability |
139-
| `DEFAULT value` | ❌ Not allowed | Use `= value` syntax after type |
138+
| `NOT NULL` / `NULL` | ❌ Not allowed | Use `= NULL` for nullable; omit default for required |
139+
| `DEFAULT value` | ❌ Not allowed | Use `= value` syntax before the type |
140140
| `PRIMARY KEY` | ❌ Not allowed | Position above `---` line |
141141
| `UNIQUE` | ❌ Not allowed | Use DataJoint index syntax |
142142
| `COMMENT 'text'` | ❌ Not allowed | Use `# comment` syntax |
@@ -145,6 +145,20 @@ declarative syntax:
145145
| `AUTO_INCREMENT` | ⚠️ Discouraged | Allowed with native types only, generates warning |
146146
| `UNSIGNED` | ✅ Allowed | Part of type semantics (use `uint*` core types) |
147147

148+
**Nullability and defaults:** DataJoint handles nullability through the default value syntax.
149+
An attribute is nullable if and only if its default is `NULL`:
150+
151+
```
152+
# Required (NOT NULL, no default)
153+
name : varchar(100)
154+
155+
# Nullable (default is NULL)
156+
nickname = NULL : varchar(100)
157+
158+
# Required with default value
159+
status = "active" : varchar(20)
160+
```
161+
148162
**Auto-increment policy:** DataJoint discourages `AUTO_INCREMENT` / `SERIAL` because:
149163
- Breaks reproducibility (IDs depend on insertion order)
150164
- Makes pipelines non-deterministic

0 commit comments

Comments
 (0)