Skip to content

Commit 6e33ebd

Browse files
knethamotl
authored andcommitted
Driver/Go: Fix code snippet
1 parent 0fe1681 commit 6e33ebd

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

docs/connect/go.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,24 @@ import (
2424
"context"
2525
"fmt"
2626
"os"
27-
27+
2828
"github.com/jackc/pgx/v5"
2929
)
3030

3131
func main() {
3232

33+
3334
ctx := context.Background()
3435

3536
// urlExample := "postgres://username:password@localhost:5432/schema_name"
36-
conn, err := pgx.Connect(ctx, os.Getenv("DATABASE_URL"))
37+
conn, err := pgx.Connect(ctx, os.Getenv("CRATEDB_URL"))
3738
if err != nil {
3839
fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err)
3940
os.Exit(1)
4041
}
41-
defer conn.Close(ctx)
42-
43-
err = conn.Query(ctx, "SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3").Scan()
42+
defer conn.Close(context.Background())
43+
44+
rows, err := conn.Query(ctx, "SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3")
4445
if err != nil {
4546
fmt.Fprintf(os.Stderr, "Query failed: %v\n", err)
4647
os.Exit(1)
@@ -53,7 +54,7 @@ func main() {
5354
fmt.Fprintf(os.Stderr, "Scan failed: %v\n", err)
5455
os.Exit(1)
5556
}
56-
fmt.Println(name, height)
57+
fmt.Println(mountain, height)
5758
}
5859
if err := rows.Err(); err != nil {
5960
fmt.Fprintf(os.Stderr, "Rows error: %v\n", err)

0 commit comments

Comments
 (0)