-
Notifications
You must be signed in to change notification settings - Fork 654
Expand file tree
/
Copy pathbfloat16.go
More file actions
70 lines (56 loc) · 1.18 KB
/
bfloat16.go
File metadata and controls
70 lines (56 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package std
import (
"context"
"database/sql"
"fmt"
"github.com/ClickHouse/clickhouse-go/v2"
)
func BFloat16() error {
conn, err := GetStdOpenDBConnection(clickhouse.Native, nil, nil, nil)
if err != nil {
return err
}
ctx := context.Background()
_, err = conn.ExecContext(ctx, "DROP TABLE IF EXISTS example")
if err != nil {
return nil
}
const ddl = `
CREATE TABLE example (
Col1 BFloat16,
Col2 Nullable(BFloat16)
) Engine MergeTree() ORDER BY tuple()
`
if _, err := conn.ExecContext(ctx, ddl); err != nil {
return nil
}
fmt.Println("Table created")
scope, err := conn.Begin()
if err != nil {
return err
}
batch, err := scope.PrepareContext(ctx, "INSERT INTO example")
if err != nil {
return err
}
_, err = batch.ExecContext(ctx, float32(33.125), sql.NullFloat64{
Float64: 34.25,
Valid: true,
})
if err != nil {
return err
}
if err := scope.Commit(); err != nil {
return err
}
fmt.Println("Values inserted")
var (
col1 float32
col2 sql.NullFloat64
)
if err := conn.QueryRowContext(ctx, "SELECT * FROM example").Scan(&col1, &col2); err != nil {
return nil
}
fmt.Printf("Col1: %v, Col2: %v\n", col1, col2)
return nil
}