go-clickhouse
go-clickhouse copied to clipboard
wrong length of string selected from FixedString field
Hi all,
My table contains FixedString(8) field and it's exactly 8 bytes length:
select fee_asset, length(fee_asset) from log limit 1
| BTC | 8 |
But receiving this field using SELECT
statement and your driver I always receive 12 bytes string:
BTC \0\0\0\0
.
To get value I'm using Scan
method for sql.Rows.
Is it expected and I'm doing something wrong?
Any updates on this?
Just use 'toStringCutToZero' on string column in your query
What additional 4 bytes mean in that case and why I should to cut them manually?
When I use driver which uses native tcp protocol there is no such problem.
Look here https://clickhouse.tech/docs/en/sql-reference/data-types/fixedstring/ I was experienced this behaviour also, and just fixed my query like so `SELECT toStringCutToZero(SomeFixedStringColumn) as String,
from some_table GROUP BY String;`
https://clickhouse.tech/docs/en/sql-reference/functions/type-conversion-functions/#tostringcuttozeros
Hi! Indeed a good idea to work on the driver so it will cut the \0\0\0. PR is welcome