Skip to content

fix: stop declaring a column type the storage will not match - #239

Merged
nao1215 merged 2 commits into
mainfrom
fix/numeric-detection-rejects-go-only-literals
Aug 6, 2026
Merged

fix: stop declaring a column type the storage will not match#239
nao1215 merged 2 commits into
mainfrom
fix/numeric-detection-rejects-go-only-literals

Conversation

@nao1215

@nao1215 nao1215 commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Summary

Column type detection could declare INTEGER or REAL for a column whose values SQLite then stored as text, so the schema a caller reads and typeof() disagreed with no way to tell from the outside. Two independent triggers, both fixed here.

Changes

  • types.go: isFloat rejects numeric syntax that only Go accepts, via a new hasGoOnlyNumericSyntax helper. strconv.ParseFloat takes a digit-separating underscore (1_000, 1_000.5) and a hexadecimal float (0x1p4); SQL takes neither, so those values were called REAL and stored as text.
  • types.go: selectColumnType returns text when a column holds a datetime alongside a number. A datetime is stored as text, so there is no type covering both, which is the rule the function already applied to text values.
  • types_test.go: cases for both triggers in TestIsFloat and TestSelectColumnType.
  • CHANGELOG.md.

Design Decisions

The rule for text was already at the top of selectColumnType: if any value in the column is text, the column is text, because no other type holds it. A datetime value is stored as text too, so the same reasoning applies and the fix is that rule extended rather than a new confidence tweak. Going by confidence instead is what let three integers and four reals outvote two datetimes and declare REAL over values that were never numeric.

For the literal syntax the check is a small explicit test rather than a stricter regex over the whole value, because ParseFloat is otherwise the right acceptor and only these two Go-only spellings need excluding. Binary (0b101) and octal (0o17) literals already failed ParseFloat and need no handling.

Limitations

One existing TestSelectColumnType case pinned the old answer: three integers, four reals, and two datetimes returned REAL. That is the behavior being fixed, so its expectation is now text, and a datetime-free version of the case keeps covering the numeric fallback it was written for.

Summary by CodeRabbit

  • Bug Fixes

    • Corrected column type detection for unsupported numeric formats, including hexadecimal, binary, octal, and underscore-separated values.
    • Columns mixing date/time and numeric values are now classified as TEXT, matching SQLite behavior.
    • Improved handling of mixed integer and decimal values based on the most common type.
  • Tests

    • Added coverage for numeric parsing and mixed-type column classification.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 431d2d57-d8e8-4625-b09b-1bfff7ebe17f

📥 Commits

Reviewing files that changed from the base of the PR and between 1c43039 and d421eb3.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • types.go
  • types_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • CHANGELOG.md
  • types_test.go
  • types.go

📝 Walkthrough

Walkthrough

Changes

The change updates numeric detection and column type inference. Go-only numeric syntax remains TEXT. Columns that mix datetime and numeric values now remain TEXT. Tests cover both behaviors and preserve valid numeric inference.

Column type detection

Layer / File(s) Summary
Reject Go-only numeric syntax
types.go, types_test.go
isFloat rejects underscore-separated, hexadecimal, binary, and octal numeric syntax before parsing.
Handle mixed datetime and numeric values
types.go, types_test.go, CHANGELOG.md
selectColumnType returns TEXT for datetime and numeric mixtures. Tests preserve REAL selection for low-confidence integer/real mixtures. The changelog records the corrected behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: aligning declared column types with SQLite storage behavior.
Description check ✅ Passed The description clearly explains the problem, behavior changes, implementation, tests, design decisions, and changelog update.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/numeric-detection-rejects-go-only-literals

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

This comment has been minimized.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@types.go`:
- Around line 662-665: Remove the claim that SQLite rejects digit-separating
underscores, while preserving the explanation that imported or bound text
literals can be rejected by numeric affinity conversion and stored as text.
Apply this wording update in types.go:662-665, types_test.go:716-718, and
CHANGELOG.md:12; update each site consistently, with no other behavior changes.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b40fbd36-2ddc-4acb-ba66-b16e149c6115

📥 Commits

Reviewing files that changed from the base of the PR and between 0e13465 and 1c43039.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • types.go
  • types_test.go

Comment thread types.go Outdated
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

Code Metrics Report

main (0e13465) #239 (e49b2d9) +/-
Coverage 89.9% 89.9% -0.1%
Test Execution Time 18s 13s -5s
Details
  |                     | main (0e13465) | #239 (e49b2d9) |  +/-  |
  |---------------------|----------------|----------------|-------|
- | Coverage            |          89.9% |          89.9% | -0.1% |
  |   Files             |             58 |             58 |     0 |
  |   Lines             |           9991 |          10000 |    +9 |
+ |   Covered           |           8985 |           8992 |    +7 |
+ | Test Execution Time |            18s |            13s |   -5s |

Code coverage of files in pull request scope (92.9% → 92.4%)

Files Coverage +/- Status
types.go 92.4% -0.6% modified

Reported by octocov

@nao1215
nao1215 merged commit 5724e31 into main Aug 6, 2026
11 checks passed
@nao1215
nao1215 deleted the fix/numeric-detection-rejects-go-only-literals branch August 6, 2026 12:45
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