Skip to content

Commit cd3bc77

Browse files
committed
added example for explain query usning table service
1 parent f9d63e0 commit cd3bc77

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

table/example_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,34 @@ func Example_select() {
6262
}
6363
}
6464

65+
func Example_explainQuery() {
66+
ctx := context.TODO()
67+
db, err := ydb.Open(ctx, "grpc://localhost:2136/local")
68+
if err != nil {
69+
fmt.Printf("failed connect: %v", err)
70+
71+
return
72+
}
73+
defer db.Close(ctx) // cleanup resources
74+
err = db.Table().Do( // Do retry operation on errors with best effort
75+
ctx, // context manage exiting from Do
76+
func(ctx context.Context, s table.Session) (err error) { // retry operation
77+
explanation, err := s.Explain(ctx, `SELECT 42 as id, "my string" as myStr`)
78+
if err != nil {
79+
return err // for auto-retry with driver
80+
}
81+
82+
fmt.Printf("plan: %s\n\nAST: %s", explanation.Plan, explanation.AST)
83+
84+
return nil
85+
},
86+
table.WithIdempotent(),
87+
)
88+
if err != nil {
89+
fmt.Printf("unexpected error: %v", err)
90+
}
91+
}
92+
6593
func Example_createTable() {
6694
ctx := context.TODO()
6795
db, err := ydb.Open(ctx, "grpc://localhost:2136/local")

0 commit comments

Comments
 (0)