go-clickhouse icon indicating copy to clipboard operation
go-clickhouse copied to clipboard

wrong length of string selected from FixedString field

Open forward32 opened this issue 5 years ago • 5 comments

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?

forward32 avatar May 30 '19 11:05 forward32

Any updates on this?

forward32 avatar Jan 24 '20 07:01 forward32

Just use 'toStringCutToZero' on string column in your query

KnBrBz avatar Aug 05 '20 08:08 KnBrBz

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.

forward32 avatar Aug 05 '20 10:08 forward32

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

KnBrBz avatar Aug 05 '20 13:08 KnBrBz

Hi! Indeed a good idea to work on the driver so it will cut the \0\0\0. PR is welcome

DoubleDi avatar Jun 06 '21 17:06 DoubleDi