Ecto. Adapters. ClickHouse. Types. FixedString
(clickhouse_adapter_ecto v0.2.0)
Copy Markdown
An Ecto.ParameterizedType for ClickHouse's FixedString(N) column type.
Use it in a schema like any other parameterized type:
schema "widgets" do
field :code, Ecto.Adapters.ClickHouse.Types.FixedString, size: 16
endsize (a positive integer, the N in FixedString(N)) is required and
validated when the schema module compiles, not on the first cast.
Value semantics
FixedString(N) always occupies exactly N bytes on the wire.
ClickHouse zero-pads a shorter value up to N on insert, and rejects a
value longer than N bytes with DB::Exception code 131 ("Too large
string for FixedString column"). A SELECT returns those N bytes
verbatim, padding included -- ClickHouse doesn't strip it back out, and
neither does this type.
cast/2 rejects a binary longer than size, but doesn't pad a shorter
one itself (ClickHouse's own INSERT already does that). load/3
returns the padded bytes exactly as decoded -- if you store binary data
whose natural encoding ends in zero bytes, those bytes are preserved
rather than trimmed.