Skip to content
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

Closed
pjebs opened this issue Jul 11, 2019 · 17 comments
Closed

proposal: go 2: database/sql: ColumnType #33066

pjebs opened this issue Jul 11, 2019 · 17 comments

Comments

@pjebs
Copy link
Contributor

pjebs commented Jul 11, 2019

ColumnType should also provide if column is unsigned or not

@gopherbot gopherbot added this to the Proposal milestone Jul 11, 2019
@pjebs pjebs changed the title proposal: go 2: database/sql: column type proposal: go 2: database/sql: ColumnType Jul 11, 2019
@kardianos
Copy link
Contributor

What database support unsigned integers?

@kardianos kardianos self-assigned this Jul 12, 2019
@pjebs
Copy link
Contributor Author

pjebs commented Jul 12, 2019

Mysql

@kardianos
Copy link
Contributor

Thanks for the ref.

Wouldn't the DatabaseTypeName be "BIGINT UNSIGNED" or "INT UNSIGNED", and the ScanType be uint64 or uint32?

@renthraysk
Copy link

ScanType will only be correct for non null columns, otherwise it'll be a Null* type.

@pjebs
Copy link
Contributor Author

pjebs commented Jul 13, 2019

@kardianos even if unsigned, DatabaseTypeName returns "BIGINT" or "INT" etc. doesn't return unsigned.

@kardianos
Copy link
Contributor

Okay, this sounds like a request for the mysql driver to treat unsigned ints differently then signed ints.

@pjebs
Copy link
Contributor Author

pjebs commented Jul 13, 2019

In mysql, unsigned is an attribute similar to nullable. It's not a different data type.

@lootch
Copy link

lootch commented Jul 14, 2019 via email

@pjebs
Copy link
Contributor Author

pjebs commented Jul 14, 2019

There are other fields like precision that don't apply generally

@lootch
Copy link

lootch commented Jul 14, 2019 via email

@pjebs
Copy link
Contributor Author

pjebs commented Jul 14, 2019

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.

@lootch
Copy link

lootch commented Jul 14, 2019 via email

@kardianos
Copy link
Contributor

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

@pjebs
Copy link
Contributor Author

pjebs commented Jul 14, 2019

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

@methane
Copy link
Contributor

methane commented Jul 17, 2019

From MySQL protocol view, there is no unsigned type:
https://dev.mysql.com/doc/internals/en/com-query-response.html#column-type

Note that column type of result set is not strictly equal to column type of table.
You need to query "show create table" or "desc table" to know column type of the table.

@pjebs
Copy link
Contributor Author

pjebs commented Jul 17, 2019

I don't think @kardianos is interested anymore.

@arnehormann
Copy link
Contributor

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

@golang golang locked and limited conversation to collaborators Jul 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants