diff --git a/pgtype/box.go b/pgtype/box.go index 83df0499..4c5a4406 100644 --- a/pgtype/box.go +++ b/pgtype/box.go @@ -116,8 +116,12 @@ func (src *Box) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, errUndefined } - buf = append(buf, fmt.Sprintf(`(%f,%f),(%f,%f)`, - src.P[0].X, src.P[0].Y, src.P[1].X, src.P[1].Y)...) + buf = append(buf, fmt.Sprintf(`(%s,%s),(%s,%s)`, + strconv.FormatFloat(src.P[0].X, 'f', -1, 64), + strconv.FormatFloat(src.P[0].Y, 'f', -1, 64), + strconv.FormatFloat(src.P[1].X, 'f', -1, 64), + strconv.FormatFloat(src.P[1].Y, 'f', -1, 64), + )...) return buf, nil } diff --git a/pgtype/box_test.go b/pgtype/box_test.go index f26cda68..197401f3 100644 --- a/pgtype/box_test.go +++ b/pgtype/box_test.go @@ -10,7 +10,7 @@ import ( func TestBoxTranscode(t *testing.T) { testutil.TestSuccessfulTranscode(t, "box", []interface{}{ &pgtype.Box{ - P: [2]pgtype.Vec2{{7.1, 5.234}, {3.14, 1.678}}, + P: [2]pgtype.Vec2{{7.1, 5.2345678}, {3.14, 1.678}}, Status: pgtype.Present, }, &pgtype.Box{ diff --git a/pgtype/circle.go b/pgtype/circle.go index 97ecbf31..15ea447b 100644 --- a/pgtype/circle.go +++ b/pgtype/circle.go @@ -103,7 +103,12 @@ func (src *Circle) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, errUndefined } - buf = append(buf, fmt.Sprintf(`<(%f,%f),%f>`, src.P.X, src.P.Y, src.R)...) + buf = append(buf, fmt.Sprintf(`<(%s,%s),%s>`, + strconv.FormatFloat(src.P.X, 'f', -1, 64), + strconv.FormatFloat(src.P.Y, 'f', -1, 64), + strconv.FormatFloat(src.R, 'f', -1, 64), + )...) + return buf, nil } diff --git a/pgtype/circle_test.go b/pgtype/circle_test.go index 2747d4f5..634c5832 100644 --- a/pgtype/circle_test.go +++ b/pgtype/circle_test.go @@ -9,7 +9,7 @@ import ( func TestCircleTranscode(t *testing.T) { testutil.TestSuccessfulTranscode(t, "circle", []interface{}{ - &pgtype.Circle{P: pgtype.Vec2{1.234, 5.6789}, R: 3.5, Status: pgtype.Present}, + &pgtype.Circle{P: pgtype.Vec2{1.234, 5.67890123}, R: 3.5, Status: pgtype.Present}, &pgtype.Circle{P: pgtype.Vec2{-1.234, -5.6789}, R: 12.9, Status: pgtype.Present}, &pgtype.Circle{Status: pgtype.Null}, }) diff --git a/pgtype/line.go b/pgtype/line.go index f6eadf0e..5fdc5604 100644 --- a/pgtype/line.go +++ b/pgtype/line.go @@ -101,7 +101,13 @@ func (src *Line) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, errUndefined } - return append(buf, fmt.Sprintf(`{%f,%f,%f}`, src.A, src.B, src.C)...), nil + buf = append(buf, fmt.Sprintf(`{%s,%s,%s}`, + strconv.FormatFloat(src.A, 'f', -1, 64), + strconv.FormatFloat(src.B, 'f', -1, 64), + strconv.FormatFloat(src.C, 'f', -1, 64), + )...) + + return buf, nil } func (src *Line) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { diff --git a/pgtype/line_test.go b/pgtype/line_test.go index 019cbf0c..200d1d4c 100644 --- a/pgtype/line_test.go +++ b/pgtype/line_test.go @@ -25,7 +25,7 @@ func TestLineTranscode(t *testing.T) { testutil.TestSuccessfulTranscode(t, "line", []interface{}{ &pgtype.Line{ - A: 1.23, B: 4.56, C: 7.89, + A: 1.23, B: 4.56, C: 7.89012345, Status: pgtype.Present, }, &pgtype.Line{ diff --git a/pgtype/lseg.go b/pgtype/lseg.go index a9d740cf..4445ea51 100644 --- a/pgtype/lseg.go +++ b/pgtype/lseg.go @@ -116,8 +116,13 @@ func (src *Lseg) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, errUndefined } - buf = append(buf, fmt.Sprintf(`(%f,%f),(%f,%f)`, - src.P[0].X, src.P[0].Y, src.P[1].X, src.P[1].Y)...) + buf = append(buf, fmt.Sprintf(`(%s,%s),(%s,%s)`, + strconv.FormatFloat(src.P[0].X, 'f', -1, 64), + strconv.FormatFloat(src.P[0].Y, 'f', -1, 64), + strconv.FormatFloat(src.P[1].X, 'f', -1, 64), + strconv.FormatFloat(src.P[1].Y, 'f', -1, 64), + )...) + return buf, nil } diff --git a/pgtype/lseg_test.go b/pgtype/lseg_test.go index bd394e3c..0a25090a 100644 --- a/pgtype/lseg_test.go +++ b/pgtype/lseg_test.go @@ -10,7 +10,7 @@ import ( func TestLsegTranscode(t *testing.T) { testutil.TestSuccessfulTranscode(t, "lseg", []interface{}{ &pgtype.Lseg{ - P: [2]pgtype.Vec2{{3.14, 1.678}, {7.1, 5.234}}, + P: [2]pgtype.Vec2{{3.14, 1.678}, {7.1, 5.2345678901}}, Status: pgtype.Present, }, &pgtype.Lseg{ diff --git a/pgtype/path.go b/pgtype/path.go index aa0cee8e..69083712 100644 --- a/pgtype/path.go +++ b/pgtype/path.go @@ -138,7 +138,10 @@ func (src *Path) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if i > 0 { buf = append(buf, ',') } - buf = append(buf, fmt.Sprintf(`(%f,%f)`, p.X, p.Y)...) + buf = append(buf, fmt.Sprintf(`(%s,%s)`, + strconv.FormatFloat(p.X, 'f', -1, 64), + strconv.FormatFloat(p.Y, 'f', -1, 64), + )...) } return append(buf, endByte), nil diff --git a/pgtype/path_test.go b/pgtype/path_test.go index d213a1b4..bc2d7435 100644 --- a/pgtype/path_test.go +++ b/pgtype/path_test.go @@ -10,7 +10,7 @@ import ( func TestPathTranscode(t *testing.T) { testutil.TestSuccessfulTranscode(t, "path", []interface{}{ &pgtype.Path{ - P: []pgtype.Vec2{{3.14, 1.678}, {7.1, 5.234}}, + P: []pgtype.Vec2{{3.14, 1.678901234}, {7.1, 5.234}}, Closed: false, Status: pgtype.Present, }, diff --git a/pgtype/point.go b/pgtype/point.go index 3132a939..98a32d34 100644 --- a/pgtype/point.go +++ b/pgtype/point.go @@ -98,7 +98,10 @@ func (src *Point) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, errUndefined } - return append(buf, fmt.Sprintf(`(%f,%f)`, src.P.X, src.P.Y)...), nil + return append(buf, fmt.Sprintf(`(%s,%s)`, + strconv.FormatFloat(src.P.X, 'f', -1, 64), + strconv.FormatFloat(src.P.Y, 'f', -1, 64), + )...), nil } func (src *Point) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { diff --git a/pgtype/point_test.go b/pgtype/point_test.go index f46b342d..af70b38b 100644 --- a/pgtype/point_test.go +++ b/pgtype/point_test.go @@ -9,7 +9,7 @@ import ( func TestPointTranscode(t *testing.T) { testutil.TestSuccessfulTranscode(t, "point", []interface{}{ - &pgtype.Point{P: pgtype.Vec2{1.234, 5.6789}, Status: pgtype.Present}, + &pgtype.Point{P: pgtype.Vec2{1.234, 5.6789012345}, Status: pgtype.Present}, &pgtype.Point{P: pgtype.Vec2{-1.234, -5.6789}, Status: pgtype.Present}, &pgtype.Point{Status: pgtype.Null}, }) diff --git a/pgtype/polygon.go b/pgtype/polygon.go index 3f3d9f53..d84a0abd 100644 --- a/pgtype/polygon.go +++ b/pgtype/polygon.go @@ -125,7 +125,10 @@ func (src *Polygon) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if i > 0 { buf = append(buf, ',') } - buf = append(buf, fmt.Sprintf(`(%f,%f)`, p.X, p.Y)...) + buf = append(buf, fmt.Sprintf(`(%s,%s)`, + strconv.FormatFloat(p.X, 'f', -1, 64), + strconv.FormatFloat(p.Y, 'f', -1, 64), + )...) } return append(buf, ')'), nil diff --git a/pgtype/polygon_test.go b/pgtype/polygon_test.go index 48481dc5..5ff3bbb3 100644 --- a/pgtype/polygon_test.go +++ b/pgtype/polygon_test.go @@ -10,7 +10,7 @@ import ( func TestPolygonTranscode(t *testing.T) { testutil.TestSuccessfulTranscode(t, "polygon", []interface{}{ &pgtype.Polygon{ - P: []pgtype.Vec2{{3.14, 1.678}, {7.1, 5.234}, {5.0, 3.234}}, + P: []pgtype.Vec2{{3.14, 1.678901234}, {7.1, 5.234}, {5.0, 3.234}}, Status: pgtype.Present, }, &pgtype.Polygon{