docs: expand CAST syntax reference for MySQL and MSSQL#1750
Merged
Conversation
The MSSQL CAST section was a dead-end stub ('Please refer to the MS SQL
CAST clause for details') that pointed to documentation that did not exist.
The MySQL CAST section had the right information but lacked a formal
synopsis and any worked examples.
Both sections are now rewritten following the PostgreSQL documentation
style: a BNF-style Synopsis block, a Guards section covering every
accepted guard, an Options section explaining the default behaviour for
each option, and an Examples section with copy-pasteable snippets.
Key improvements
----------------
mssql.rst — CAST section completely replaced:
- Synopsis in BNF notation: both the type and column match forms with
their guards and options
- Explains that the built-in defaults map char/nchar/varchar/nvarchar/
ntext to text and drop the typemod — the source of the nvarchar(40)→text
surprise reported in issue #1538
- Documents the drop/keep typemod option with an explicit before/after
example (nvarchar(40) → varchar(40) with keep typemod)
- Shows how to handle nvarchar(max) (precision = -1) separately from
fixed-length nvarchar columns
- Documents every guard available for MSSQL sources
mysql.rst — CAST section reorganised:
- Replaces the terse two-line synopsis with a full BNF-style Synopsis
- Adds a Guards subsection that covers all six guard forms (including
when signed and and not null, which were undocumented)
- Rewrites the options as a flat definition list with clearer language
about what the default behaviour is for each option
- Adds an Examples subsection with three representative patterns:
* Preserving varchar/char length modifiers (keep typemod)
* Mapping tinyint(1) to boolean vs smallint
* Handling auto_increment with serial/bigserial
Docs build with sphinx-build (HTML target) succeeds with no new warnings.
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.
Problem (ref #1538)
The MSSQL CAST section was a dead-end stub:
…pointing to documentation that did not exist. The MySQL CAST section had the right information scattered across bullet lists but lacked a formal synopsis and any worked examples showing what actually happens to the data type.
The confusion surfaces in issue #1538: a user with
nvarchar(40)columns found everything collapsing totextand could not figure out from the docs that they neededkeep typemod— or what that keyword even did.Changes
docs/ref/mssql.rst— CAST section completely replacedtypeandcolumnmatch forms with their full guard and option syntaxchar/nchar/varchar/nvarchar/ntext→textand drop the typemod — the source of thenvarchar(40)→textsurprisedrop typemod/keep typemoddocumented with explicit before/after:nvarchar(40)→varchar(40)withkeep typemodnvarchar(max)(precision = −1) separately; override a single columnwhen default,when (typemod_expression),and not null)docs/ref/mysql.rst— CAST section reorganisedwhen signedandand not nullwhich were entirely undocumenteddrop typemod") so users know what they get without specifying anythingvarchar/charlength modifiers withkeep typemodtinyint(1)tobooleanvssmallintauto_incrementwithserial/bigserialBuild
Succeeds with no new warnings (two pre-existing warnings unrelated to this change).