-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: go 2: database/sql: ColumnType #33066
Comments
What database support unsigned integers? |
Mysql |
Thanks for the ref. Wouldn't the DatabaseTypeName be "BIGINT UNSIGNED" or "INT UNSIGNED", and the ScanType be uint64 or uint32? |
ScanType will only be correct for non null columns, otherwise it'll be a Null* type. |
@kardianos even if unsigned, DatabaseTypeName returns "BIGINT" or "INT" etc. doesn't return unsigned. |
Okay, this sounds like a request for the mysql driver to treat unsigned ints differently then signed ints. |
In mysql, unsigned is an attribute similar to nullable. It's not a different data type. |
On 7/13/19, pj ***@***.***> wrote:
In mysql, unsigned is an attribute similar to nullable.
Nullable is surely applicable to any SQL field, whereas unsigned can
only apply to numerics?
Lucio.
|
There are other fields like precision that don't apply generally |
On 7/14/19, pj ***@***.***> wrote:
There are other fields like precision that don't apply generally
My point (more a question, really) is that unsigned is not the same as
nullable even in the mysql context, precisely because it does not
apply genericaly. I'm not sure how unique mysql is in this respect,
but treating the two as analogous doesn't sound like the right
approach.
Lucio.
|
My point is ColumnType already has functions such as precision that don't apply generally. There should be another called unsigned. If it's not applicable to the column then return a second value of false. |
On 7/14/19, pj ***@***.***> wrote:
My point is ColumnType already has functions such as precision that don't
apply generally. There should be another called unsigned. If it's not
applicable the return a second value of false.
That does sound quite definitive, and not likely to break the API you
suggest it belongs to. But it is an API enhancement and perhaps ought
to be restricted to the "mysql" driver. As a pgsql follower, I would
not expect the signedness of a column to be of interest to me.
It also sees odd that this issue would first raise its head so long
after the various APIs were first introduced. But I tend to stray as
little as possible from some imaginary SQL-conforming use so my lack
of exposure need not be much of an indication.
Perhaps there is an alternative packaging for wilder SQL mutations
that can exploit their features more efficiently than the database/sql
+ driver combination?
Lucio.
|
@pjebs In Go, a uint32 and int32 are distinct types, as they have different ranges. In SQL the UNSIGNED is a MySQL specific extension. The DatabaseTypeName needs to be matchable like in a simple switch statement, so we put Length, precision, and scale in integer values so they wouldn't need to be parsed. Furthermore, decimals are standard SQL types and very important for many business applications. NULL is a third value and required to support things like not-present and left joins. NULL or Nullable is not an attribute like "unsigned" which fundamentally changes the data that it can hold. "INT" and "INT UNSIGNED" do not need to be parsed only matched. The unsigned bit doesn't need a separate field. I'm rejecting this proposal. Feel free to open an issue with the MySQL driver to differentiate between "INT" and "INT UNSIGNED" if it doesn't do so already. |
I can see from your point of view why you think it's just a semantic issue, but from mysql user's point of view we don't consider unsigned as a different "Type". It's a modifier of a type. So it's unlikely the maintainers of mysql driver would change it: @methane @julienschmidt @arnehormann |
From MySQL protocol view, there is no unsigned type: Note that column type of result set is not strictly equal to column type of table. |
I don't think @kardianos is interested anymore. |
@pjebs I have https://godoc.org/github.com/arnehormann/sqlinternals/mysqlinternals and it worked splendidly. It's currently stale, though - some fields changed. It predates the whole go sql ColumnType but is ugly insofar as it uses unsafe. If it would help you, I can update it. |
ColumnType should also provide if column is unsigned or not
The text was updated successfully, but these errors were encountered: