Skip to content

Instantly share code, notes, and snippets.

@mlh758
Created February 10, 2020 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlh758/265b5f5cfae08450cf04aec639033986 to your computer and use it in GitHub Desktop.
Save mlh758/265b5f5cfae08450cf04aec639033986 to your computer and use it in GitHub Desktop.
Vertica Test
module github.com/mlh758/vertica
go 1.13
require github.com/vertica/vertica-sql-go v0.1.7
replace github.com/vertica/vertica-sql-go => /path/to/vertica-sql-go
package main
import (
"database/sql"
"log"
"os"
"os/signal"
"time"
_ "github.com/vertica/vertica-sql-go"
)
func main() {
db := openDB()
done := make(chan struct{})
ticker := time.NewTicker(10 * time.Second)
go func() {
for {
select {
case <-done:
return
case <-ticker.C:
rows, err := db.Query("SELECT DISTINCT(keyword) FROM v_catalog.standard_keywords WHERE reserved='R' LIMIT 10")
if err != nil {
log.Println(err)
} else {
rows.Close()
log.Println("Query ran.")
}
}
}
}()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
done <- struct{}{}
db.Close()
}
func openDB() *sql.DB {
db, err := sql.Open("vertica", "vertica://mike:pass@localhost:5433/mike")
if err != nil {
log.Fatal(err)
}
return db
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment