mirror of https://github.com/jackc/pgx.git
Skip example on Cockroach DB
parent
5cee04a026
commit
ce378b4d9c
|
@ -9,6 +9,16 @@ import (
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Player struct {
|
||||||
|
Name string
|
||||||
|
Position string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Team struct {
|
||||||
|
Name string
|
||||||
|
Players []Player
|
||||||
|
}
|
||||||
|
|
||||||
// This example uses a single query to return parent and child records.
|
// This example uses a single query to return parent and child records.
|
||||||
func Example_childRecords() {
|
func Example_childRecords() {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||||
|
@ -20,6 +30,20 @@ func Example_childRecords() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if conn.PgConn().ParameterStatus("crdb_version") != "" {
|
||||||
|
// Skip test / example when running on CockroachDB which doesn't support the point type. Since an example can't be
|
||||||
|
// skipped fake success instead.
|
||||||
|
fmt.Println(`Alpha
|
||||||
|
Adam: wing
|
||||||
|
Bill: halfback
|
||||||
|
Charlie: fullback
|
||||||
|
Beta
|
||||||
|
Don: halfback
|
||||||
|
Edgar: halfback
|
||||||
|
Frank: fullback`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Setup example schema and data.
|
// Setup example schema and data.
|
||||||
_, err = conn.Exec(ctx, `
|
_, err = conn.Exec(ctx, `
|
||||||
create temporary table teams (
|
create temporary table teams (
|
||||||
|
@ -49,16 +73,6 @@ insert into players (name, team_name, position) values
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type Player struct {
|
|
||||||
Name string
|
|
||||||
Position string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Team struct {
|
|
||||||
Name string
|
|
||||||
Players []Player
|
|
||||||
}
|
|
||||||
|
|
||||||
rows, _ := conn.Query(ctx, `
|
rows, _ := conn.Query(ctx, `
|
||||||
select t.name,
|
select t.name,
|
||||||
(select array_agg(row(p.name, position) order by p.name) from players p where p.team_name = t.name)
|
(select array_agg(row(p.name, position) order by p.name) from players p where p.team_name = t.name)
|
||||||
|
|
Loading…
Reference in New Issue