8000 docs(spec): state the JSON form of every type each database writes by colinhacks · Pull Request #159 · colinhacks/reylo · GitHub
[go: up one dir, main page]

Skip to content

docs(spec): state the JSON form of every type each database writes - #159

Merged
colinhacks merged 2 commits into
mainfrom
spec-json-facts
Nov 3, 2026
Merged

colinhacks merged 2 commits into
mainfrom
spec-json-facts

Conversation

@colinhacks
Copy link
Copy Markdown
Owner

The spec types each leaf of JSON content by the SQL value the database wrote it from, and its facts listed only five forms per database. Most of the types the spec structures are written as plain strings inside JSON, so a consumer reading a leaf by its type alone would expect a JSON array or object where the database wrote text.

Measured on Postgres 18 and MySQL 8.4:

select json_build_object('bit', B'101'::bit(3), 'point', point(1,2), 'inet', '10.0.0.1/8'::inet, 'range', int4range(1,5), 'interval', interval '1 mon -1 day', 'bytea', '\x0102'::bytea, 'oid', 26::oid)
{"bit" : "101", "point" : "(1,2)", "inet" : "10.0.0.1/8", "range" : "[1,5)", "interval" : "1 mon -1 days", "bytea" : "\\x0102", "oid" : "26"}

select json_object('s', s, 't', t, 'y', y, 'point', point(1,2)) from j   -- s set('a','b'), t time(2), y year
{"s": "a,b", "t": "12:00:01.500000", "y": 2026, "point": {"type": "Point", "coordinates": [1.0, 2.0]}}

The facts now state each database's general rule: on Postgres, booleans, numbers, dates and timestamps, arrays, rows, hstore and PostGIS geometry have JSON forms of their own and every other type is a string of its text; on MySQL, TIME, YEAR, ENUM, SET, BIT and spatial values are added.

Copilot AI balanced review requested due to automatic review settings November 2, 2026 22:58
@vercel
vercel Bot commented Nov 2, 2026 •
Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
reylo Error Error Nov 2, 2026 11:09pm UTC

Request Review

Copilot AI left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The type-descriptor documentation misclassifies several numeric types as JSON strings and incorrectly describes hexadecimal as the only bytea encoding.

2 open issues
What changed in this PR

This documentation-only PR expands the type descriptor specification’s JSON representation rules, clarifying how database-generated JSON relates to SQL leaf types.

Changes:

  • Documents Postgres JSON forms for additional types and a text-string fallback.
  • Adds MySQL rules for temporal, enum, set, bit and spatial values.
  • Leaves executable code and type definitions unchanged.
File Description
spec/​type-descriptor.ts Expands comments describing Postgres and MySQL JSON representations.

Review effort: Balanced

Comment thread spec/type-descriptor.ts Outdated
// - Postgres:
// - a `numeric` is a JSON number of any length, and a NaN or Infinity a string;
// - a `boolean` is `true` or `false`;
// - a `numeric` is a JSON number of any length, and a float's or a `numeric`'s NaN or Infinity a string;
Comment thread spec/type-descriptor.ts Outdated
// - an array is a JSON array of its elements, and a composite or any other row an object of its fields (`row(1, 'x')` is `{"f1":1,"f2":"x"}`);
// - an `hstore` is an object of nullable text, and PostGIS's `geometry` GeoJSON;
// - `jsonb` sorts keys and keeps the last duplicate, while `json` keeps the text as written;
// - every other type is a string of its text, structured or not: `bit` and `varbit` (`"101"`), the geometric types (`"(1,2)"`, `"[(0,0),(1,1)]"`), `inet`, `cidr`, `macaddr` and `macaddr8`, ranges and multiranges (`"[1,5)"`), `interval` in the session's IntervalStyle (`"1 mon -1 days"`), `time`, `uuid`, `money`, `oid`, `xml`, and `bytea` in hex (`"\\x0102"`).
@pullfrog pullfrog Bot left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Two gaps the new catch-all opens. Details inline.

Reviewed changes

Reviewed the update to the spec's facts on what Postgres and MySQL write inside their own JSON.

  • Postgres general rule: adds booleans, date/timestamp, arrays, rows, PostGIS geometry, and a catch-all saying every other type is a string of its text.
  • MySQL additions: TIME, YEAR, ENUM, SET, BIT and spatial values.

The MySQL claims match Json_wrapper's output. On Postgres, json_categorize_type agrees with the structured cases and with oid as a string. Two things are off because the new catch-all now applies to every type the list doesn't name.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using claude-opus-5-5 | 𝕏

Comment thread spec/type-descriptor.ts Resolved
Comment thread spec/type-descriptor.ts Resolved
Comment thread spec/type-descriptor.ts Resolved
@pullfrog pullfrog Bot left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found. All three earlier comments are fixed.

Reviewed changes

Reviewed 67fdd74, which revises the Postgres list of JSON forms in response to the earlier review.

  • Postgres numbers: now says integers, floats and numeric are all JSON numbers. A float's or a numeric's NaN or Infinity is a string. This matches json_categorize_type's JSONTYPE_NUMERIC group and the check that quotes text IsValidJsonNumber rejects.
  • Postgres dates: now gives the BC suffix and "infinity"/"-infinity" for all three of date, timestamp and timestamptz. This matches EncodeDateOnly/EncodeDateTime under USE_XSD_DATES and EncodeSpecialDate/EncodeSpecialTimestamp.
  • bytea: now written in the session's bytea_output, hex by default, the same way interval follows IntervalStyle.

Pullfrog  | View workflow run | Using claude-opus-5-5 | 𝕏

@colinhacks
colinhacks merged commit 89b137b into main Nov 3, 2026
9 of 10 checks passed
@colinhacks
colinhacks deleted the spec-json-facts branch November 3, 2026 00:11
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.

2 participants

0