-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Expand file tree
/
Copy pathcolumnstore.go
More file actions
51 lines (42 loc) · 1.03 KB
/
columnstore.go
File metadata and controls
51 lines (42 loc) · 1.03 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
package main
import (
"database/sql"
"fmt"
"log"
"time"
_ "github.com/denisenkom/go-mssqldb"
)
var (
server = "localhost"
port = 1433
user = "sa"
password = "your_password"
database = "SampleDB"
)
// ExecuteAggregateStatement output summary of prices
func ExecuteAggregateStatement(db *sql.DB) {
result, err := db.Prepare("SELECT SUM(Price) as sum FROM Table_with_5M_rows")
if err != nil {
fmt.Println("Error preparing query: " + err.Error())
}
row := result.QueryRow()
var sum string
err = row.Scan(&sum)
fmt.Printf("Sum: %s\n", sum)
}
func main() {
// Connect to database
connString := fmt.Sprintf("server=%s;user id=%s;password=%s;port=%d;database=%s;",
server, user, password, port, database)
conn, err := sql.Open("mssql", connString)
if err != nil {
log.Fatal("Open connection failed:", err.Error())
}
fmt.Printf("Connected!\n")
defer conn.Close()
t1 := time.Now()
fmt.Printf("Start time: %s\n", t1)
ExecuteAggregateStatement(conn)
t2 := time.Since(t1)
fmt.Printf("The query took: %s\n", t2)
}