Created
February 10, 2020 18:23
-
-
Save mlh758/265b5f5cfae08450cf04aec639033986 to your computer and use it in GitHub Desktop.
Vertica Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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