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

Support inserting Enums as int8/int16/int values #802

Merged
merged 1 commit into from
Nov 1, 2022

Conversation

mdonkers
Copy link
Contributor

Enum values in ClickHouse are always stored as numeric (Int8 or Int16) values. While normally they will be retrieved as String values in Golang, in queries its perfectly fine to insert them as the numeric value.

Customers might have their reasons to insert as numeric value instead of the string value. Extend the API so batch inserts support this, as currently you would get the error:

        	Error:      	Received unexpected error:
        	            	clickhouse [AppendRow]: auth_type clickhouse [AppendRow]: converting int8 to Enum8 is unsupported

@mdonkers
Copy link
Contributor Author

Next to the type-specific int8 and int16 I've also decided to use the generic Golang int for convenience.
Because internally the library holds a mapping between integer and string values, and this is checked, even if the int value would be out of range the mapping would not exist and still ('gracefully') fail.

Copy link
Collaborator

@gingerwizard gingerwizard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks @mdonkers

@gingerwizard gingerwizard merged commit d2b0d99 into main Nov 1, 2022
@gingerwizard
Copy link
Collaborator

Just a thought, wouldn't uint have made more sense here? afaik, enums cant be signed

gingerwizard added a commit that referenced this pull request Nov 1, 2022
@mdonkers
Copy link
Contributor Author

mdonkers commented Nov 1, 2022

Just a thought, wouldn't uint have made more sense here? afaik, enums cant be signed

@gingerwizard strangely, enums are signed and thus can be negative: https://clickhouse.com/docs/en/sql-reference/data-types/enum/

Thanks for merging!

@mdonkers mdonkers deleted the enum-insert-as-int branch November 1, 2022 10:07
@gingerwizard
Copy link
Collaborator

ha surprising and i should of checked docs. Cheers @mdonkers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants