You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The example schema, below, illustrates several issues with the MySQL/golang numeric type mappings used to generate models right now:
The input domain for UNSIGNED types are truncated to N/2 - 1 due to golang's 2s' compliment encoding of signed integers: e.g. an INTEGER UNSIGNED MySQL type has a domain of 0..4294967295, but the parameter-type generated for an Exec statement in golang has an int32 field, with a domain of -2147483648..2147483647.
In addition to limiting the upper bound of possible values, the MySQL Driver rejects negative values with an error in this case even though golang compiles them as valid code:
panic: Error 1264: Out of range value for column 'regular_number' at row 1
Existing table rows with values outside of their respective signed type's 2s' compliment upper bound will be inaccessible for code generated by sqlc. The MySQL driver will always return a range error when it attempts to coerce unsigned values in the upper half of the type's domain into signed values. Even assuming that all of the system's input data was also truncated by the behavior above, DEFAULT or AUTO INCREMENT expressions may still generate values that break the generated code; e.g. my_id BIGINT UNSIGNED DEFAULT UUID_SHORT().
Relevant log output
No response
Database schema
CREATETABLEtestdata (
somekey INTEGERPRIMARY KEY AUTO_INCREMENT,
little_number TINYINT UNSIGNED NOT NULL, -- 8-bit
regular_number INTEGER UNSIGNED NOT NULL, -- 32-bit
huge_number BIGINT UNSIGNED NOT NULL-- 64-bit
) ENGINE = InnoDB;
Version
1.14.0
What happened?
The example schema, below, illustrates several issues with the MySQL/golang numeric type mappings used to generate models right now:
The input domain for
UNSIGNED
types are truncated toN/2 - 1
due to golang's 2s' compliment encoding of signed integers: e.g. anINTEGER UNSIGNED
MySQL type has a domain of0..4294967295
, but the parameter-type generated for an Exec statement in golang has anint32
field, with a domain of-2147483648..2147483647
.In addition to limiting the upper bound of possible values, the MySQL Driver rejects negative values with an error in this case even though golang compiles them as valid code:
results in
Existing table rows with values outside of their respective signed type's 2s' compliment upper bound will be inaccessible for code generated by
sqlc
. The MySQL driver will always return a range error when it attempts to coerce unsigned values in the upper half of the type's domain into signed values. Even assuming that all of the system's input data was also truncated by the behavior above,DEFAULT
orAUTO INCREMENT
expressions may still generate values that break the generated code; e.g.my_id BIGINT UNSIGNED DEFAULT UUID_SHORT()
.Relevant log output
No response
Database schema
SQL queries
Configuration
Playground URL
https://play.sqlc.dev/p/c96c8b00d07b7b9840c817f3768f656d7b8b39a5f93d7519b570585232b4d6aa
What operating system are you using?
Linux, macOS
What database engines are you using?
MySQL
What type of code are you generating?
Go
The text was updated successfully, but these errors were encountered: