Repository navigation
Definition syntax: string defaults and when NULL applies - #323
Open
dimitri-yatsenko wants to merge 4 commits into
Open
dimitri-yatsenko wants to merge 4 commits into
dimitri-yatsenko wants to merge 4 commits into
Conversation
…uthor Rephrase the empty-string rule as an instruction and define optional, write the NULL and '' tests as restrictions, show the reading side of the consent example, note that an enum default of '' must be among its values, and recommend varchar over char(n), which pads with spaces on PostgreSQL.
MilagrosMarin
left a comment
Collaborator
There was a problem hiding this comment.
Thanks @dimitri-yatsenko, this turns the old "rare" exception into a clear rule. I ran the examples on MySQL 8.0 and PostgreSQL 16 with 2.3.6 and current master, and almost everything matches the text:
- An enum default of
''that is not among its values is rejected when the table is declared. The error comes from the database (MySQL 1067 "Invalid default value for 'stage'"; PostgreSQL "invalid input value for enum ..."), so "rejected by the database when the table is declared" would tell readers what to expect. - An insert that omits a required string fails on both backends, as does passing
Nonefor it. Consent & "consent_note IS NULL"andConsent & {"consent_note": ""}return exactly the NULL row and the empty row on both backends.
One sentence needs narrowing:
- "Restrictions in queries give the same results on both backends" holds for equality and
IN(string or dict), but not forLIKEor other expressions on the column. Withcode = 'ab'in achar(3)column,code LIKE 'ab'andconcat(code, 'z') = 'abz'match on MySQL and return nothing on PostgreSQL. Fetched values differ too ('ab'vs'ab '), so comparisons inmake()behave differently. The padding also applies to any shorter value, not only''. Suggested: "On PostgreSQL, achar(n)column pads shorter values with spaces (''reads back asnspaces,'ab'inchar(3)as'ab '), while MySQL does not. Equality andINrestrictions match on both backends;LIKEpatterns and comparisons on fetched values do not."
Optional:
- Passing
Nonefor a non-nullable string with a''default stores''(the declared default), not NULL. A clause after "an attribute gets the default its definition declares" would head off that surprise.
With the char(n) sentence scoped to equality restrictions, this section holds on both backends.
…t rule Scope the cross-backend claim to equality and IN restrictions, since PostgreSQL pads char(n) values and LIKE patterns, expressions, and fetched values differ. Say the database rejects an enum default of '' that is not among its values. Note that None for a non-nullable string stores its declared default. Recast the rule as '' rather than NULL so it does not discourage non-empty defaults.
Member
Author
|
Thanks @MilagrosMarin for running these on both backends. All three points are now in:
I also reworded the bold rule as "use |
dimitri-yatsenko
requested review from
MilagrosMarin,
lum-agilyti and
ttngu207
December 1, 2026 23:18
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Restates the string-default rule on the definition-syntax reference page (Defaults).
varchar,char, orenum(one with a default) with the default''; DataJoint never supplies''itself. An enum that may be empty includes''in its values, and a default of''that is not among them is rejected.NULLwhen missing must be told apart from empty:NULLmeans the value is missing, and''means it is known to be empty. An example shows the declaration and the restrictions that read each case.varcharfor free text andchar(n)for fixed-width codes: on PostgreSQLchar(n)pads''tonspaces, while restrictions give the same results on both backends.The previous text allowed the same exception but described it as rare. This version states when it applies and what each value means.
Checks
mkdocs build --strict,scripts/check_markdown_lists.py, and codespell pass.