diff --git a/proto/col_nullable.go b/proto/col_nullable.go index e8e291e3..516245f0 100644 --- a/proto/col_nullable.go +++ b/proto/col_nullable.go @@ -35,7 +35,7 @@ func Null[T any]() Nullable[T] { func (n Nullable[T]) IsSet() bool { return n.Set } func (n Nullable[T]) Or(v T) T { - if n.Set { + if !n.Set { return v } return n.Value diff --git a/proto/col_nullable_test.go b/proto/col_nullable_test.go index 037fe240..6332d8e4 100644 --- a/proto/col_nullable_test.go +++ b/proto/col_nullable_test.go @@ -11,6 +11,11 @@ import ( "github.com/ClickHouse/ch-go/internal/gold" ) +func TestNullable(t *testing.T) { + require.Equal(t, Null[string]().Or("foo"), "foo") + require.Equal(t, NewNullable("bar").Or("foo"), "bar") +} + func TestColNullable_EncodeColumn(t *testing.T) { const rows = 10 data := new(ColStr).Nullable()