Do not encode Go float64 to a PostgreSQL float4

The automatic conversion of float64 to float32 could cause loss of
precision.
redshift-ssl-tests
Jack Christensen 2015-12-21 13:12:11 -06:00
parent 8577dccd65
commit 73bd33b215
2 changed files with 4 additions and 11 deletions

View File

@ -1,5 +1,6 @@
# Tip # Tip
* Go float64 can no longer be encoded to a PostgreSQL float4
* Add ConnPool.Reset method * Add ConnPool.Reset method
* []byte skips encoding/decoding * []byte skips encoding/decoding
* Rows.Scan errors now include which argument caused error * Rows.Scan errors now include which argument caused error

View File

@ -895,17 +895,9 @@ func decodeFloat4(vr *ValueReader) float32 {
} }
func encodeFloat4(w *WriteBuf, value interface{}) error { func encodeFloat4(w *WriteBuf, value interface{}) error {
var v float32 v, ok := value.(float32)
switch value := value.(type) { if !ok {
case float32: return fmt.Errorf("Expected float32, received %T", value)
v = float32(value)
case float64:
if value > math.MaxFloat32 {
return fmt.Errorf("%T %f is larger than max float32 %f", value, math.MaxFloat32)
}
v = float32(value)
default:
return fmt.Errorf("Expected float representable in float32, received %T %v", value, value)
} }
w.WriteInt32(4) w.WriteInt32(4)