Your Question
With gorm (" Gorm.io /gorm") and the sqlite driver that comes with gorm (" Gorm.io /driver/sqlite"), when storing a number of the string type, if the number is very long, then the number is stored in the database as a scientific notation, which bothers me
The document you expected this should be explained
Expected answer
I want the result is: in the long list of type string of Numbers to the database, such as "88888888888888888888888", it will not be in the form of scientific notation, exists in the database
Comment From: github-actions[bot]
This issue has been automatically marked as stale because it has been open 360 days with no activity. Remove stale label or comment or this will be closed in 180 days
Comment From: jinzhu
Thanks for reporting this.
GORM does not modify string values during insertion — if you're saving a Go string
such as "88888888888888888888888"
into a TEXT
column, it will be stored verbatim in the database.
The scientific notation you're observing is not caused by GORM or the SQLite driver (gorm.io/driver/sqlite
), but rather by how certain SQLite visualization tools (e.g., sqlite3
CLI, DB Browser for SQLite, DBeaver, etc.) render large numeric-looking strings. When such tools encounter a long string of digits, they often auto-detect it as a numeric value and apply formatting (e.g., scientific notation) on display. Internally, however, the value remains a string.
You can verify this by:
- Reading the value back via GORM into a Go
string
field — it will return the exact original value without scientific notation. - Inspecting the raw bytes via SQLite's
hex()
function to confirm the stored content. - Adding a prefix/suffix (e.g.,
"id:88888888888888888888888"
) to prevent auto-casting by client tools.
If you want to ensure SQLite treats the column strictly as text, you can annotate the model field explicitly:
``go
type Record struct {
ID string
gorm:"type=TEXT"`
}