mirror of https://github.com/jackc/pgx.git
Skipped multirange tests for postgres less than 14 version
parent
8e2de2fefa
commit
88b373f9ee
46
conn_test.go
46
conn_test.go
|
@ -911,6 +911,38 @@ func TestLoadRangeType(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer tx.Rollback(ctx)
|
defer tx.Rollback(ctx)
|
||||||
|
|
||||||
|
_, err = tx.Exec(ctx, "create type examplefloatrange as range (subtype=float8, subtype_diff=float8mi)")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Register types
|
||||||
|
newRangeType, err := conn.LoadType(ctx, "examplefloatrange")
|
||||||
|
require.NoError(t, err)
|
||||||
|
conn.TypeMap().RegisterType(newRangeType)
|
||||||
|
conn.TypeMap().RegisterDefaultPgType(pgtype.Range[float64]{}, "examplefloatrange")
|
||||||
|
|
||||||
|
var inputRangeType = pgtype.Range[float64]{
|
||||||
|
Lower: 1.0,
|
||||||
|
Upper: 2.0,
|
||||||
|
LowerType: pgtype.Inclusive,
|
||||||
|
UpperType: pgtype.Inclusive,
|
||||||
|
Valid: true,
|
||||||
|
}
|
||||||
|
var outputRangeType pgtype.Range[float64]
|
||||||
|
err = tx.QueryRow(ctx, "SELECT $1::examplefloatrange", inputRangeType).Scan(&outputRangeType)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, inputRangeType, outputRangeType)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLoadMultiRangeType(t *testing.T) {
|
||||||
|
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
|
pgxtest.SkipCockroachDB(t, conn, "Server does support range types")
|
||||||
|
pgxtest.SkipPostgreSQLVersionLessThan(t, conn, 14) // multirange data type was added in 14 postgresql
|
||||||
|
|
||||||
|
tx, err := conn.Begin(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer tx.Rollback(ctx)
|
||||||
|
|
||||||
_, err = tx.Exec(ctx, "create type examplefloatrange as range (subtype=float8, subtype_diff=float8mi, multirange_type_name=examplefloatmultirange)")
|
_, err = tx.Exec(ctx, "create type examplefloatrange as range (subtype=float8, subtype_diff=float8mi, multirange_type_name=examplefloatmultirange)")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -925,20 +957,6 @@ func TestLoadRangeType(t *testing.T) {
|
||||||
conn.TypeMap().RegisterType(newMultiRangeType)
|
conn.TypeMap().RegisterType(newMultiRangeType)
|
||||||
conn.TypeMap().RegisterDefaultPgType(pgtype.Multirange[pgtype.Range[float64]]{}, "examplefloatmultirange")
|
conn.TypeMap().RegisterDefaultPgType(pgtype.Multirange[pgtype.Range[float64]]{}, "examplefloatmultirange")
|
||||||
|
|
||||||
// Test range type
|
|
||||||
var inputRangeType = pgtype.Range[float64]{
|
|
||||||
Lower: 1.0,
|
|
||||||
Upper: 2.0,
|
|
||||||
LowerType: pgtype.Inclusive,
|
|
||||||
UpperType: pgtype.Inclusive,
|
|
||||||
Valid: true,
|
|
||||||
}
|
|
||||||
var outputRangeType pgtype.Range[float64]
|
|
||||||
err = tx.QueryRow(ctx, "SELECT $1::examplefloatrange", inputRangeType).Scan(&outputRangeType)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, inputRangeType, outputRangeType)
|
|
||||||
|
|
||||||
// Test multi range type
|
|
||||||
var inputMultiRangeType = pgtype.Multirange[pgtype.Range[float64]]{
|
var inputMultiRangeType = pgtype.Multirange[pgtype.Range[float64]]{
|
||||||
{
|
{
|
||||||
Lower: 1.0,
|
Lower: 1.0,
|
||||||
|
|
|
@ -5,6 +5,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
|
@ -151,3 +153,21 @@ func SkipCockroachDB(t testing.TB, conn *pgx.Conn, msg string) {
|
||||||
t.Skip(msg)
|
t.Skip(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SkipPostgreSQLVersionLessThan(t testing.TB, conn *pgx.Conn, minVersion int64) {
|
||||||
|
serverVersionStr := conn.PgConn().ParameterStatus("server_version")
|
||||||
|
serverVersionStr = regexp.MustCompile(`^[0-9]+`).FindString(serverVersionStr)
|
||||||
|
// if not PostgreSQL do nothing
|
||||||
|
if serverVersionStr == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
serverVersion, err := strconv.ParseInt(serverVersionStr, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("postgres version parsed failed: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if serverVersion < minVersion {
|
||||||
|
t.Skipf("Test requires PostgreSQL v%d+", minVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue