Skip to content

docs: expand CAST syntax reference for MySQL and MSSQL#1750

Merged
dimitri merged 1 commit into
mainfrom
docs/cast-syntax-reference
Jun 28, 2026
Merged

docs: expand CAST syntax reference for MySQL and MSSQL#1750
dimitri merged 1 commit into
mainfrom
docs/cast-syntax-reference

Conversation

@dimitri

@dimitri dimitri commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Problem (ref #1538)

The MSSQL CAST section was a dead-end stub:

"Please refer to the MS SQL CAST clause for details."

…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 to text and could not figure out from the docs that they needed keep typemod — or what that keyword even did.


Changes

docs/ref/mssql.rst — CAST section completely replaced

  • Synopsis in BNF notation covering both the type and column match forms with their full guard and option syntax
  • Root-cause explanation: the built-in defaults map char/nchar/varchar/nvarchar/ntexttext and drop the typemod — the source of the nvarchar(40)text surprise
  • drop typemod / keep typemod documented with explicit before/after: nvarchar(40)varchar(40) with keep typemod
  • Three copy-pasteable examples: preserve all character-type length modifiers; handle nvarchar(max) (precision = −1) separately; override a single column
  • Documents every guard available for MSSQL sources (when default, when (typemod_expression), and not null)

docs/ref/mysql.rst — CAST section reorganised

  • Replaces the terse two-line synopsis with a full BNF-style Synopsis block
  • Adds a Guards subsection covering all six guard forms, including when signed and and not null which were entirely undocumented
  • Rewrites each option as a definition-list entry that states what the default behaviour is (e.g. "many built-in rules default to drop typemod") so users know what they get without specifying anything
  • Adds an Examples subsection with three representative patterns:
    • Preserving varchar/char length modifiers with keep typemod
    • Mapping tinyint(1) to boolean vs smallint
    • Handling auto_increment with serial/bigserial

Build

cd docs && make html

Succeeds with no new warnings (two pre-existing warnings unrelated to this change).

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.
@dimitri dimitri merged commit 056c3fb into main Jun 28, 2026
37 checks passed
@dimitri dimitri deleted the docs/cast-syntax-reference branch June 28, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant