Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ go 1.26.2

require (
github.com/PuerkitoBio/goquery v1.8.1
github.com/cockroachdb/apd/v2 v2.0.3-0.20200518165714-d020e156310a
github.com/cockroachdb/apd/v3 v3.2.3
github.com/cockroachdb/errors v1.7.5
github.com/dolthub/dolt/go v0.40.5-0.20260424225502-433406d3ff75
github.com/dolthub/eventsapi_schema v0.0.0-20260310172945-37a9265ade69
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
github.com/dolthub/go-mysql-server v0.20.1-0.20260424221156-62a3b12d1f59
github.com/dolthub/go-mysql-server v0.20.1-0.20260427164548-6bc0cfa4e92a
github.com/dolthub/pg_query_go/v6 v6.0.0-20251215122834-fb20be4254d1
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216
github.com/dolthub/vitess v0.0.0-20260424215137-ec6bd432b0be
Expand Down
9 changes: 4 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ github.com/cncf/xds/go v0.0.0-20251210132809-ee656c7534f5 h1:6xNmx7iTtyBRev0+D/T
github.com/cncf/xds/go v0.0.0-20251210132809-ee656c7534f5/go.mod h1:KdCmV+x/BuvyMxRnYBlmVaq4OLiKW6iRQfvC62cvdkI=
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
github.com/cockroachdb/apd/v2 v2.0.3-0.20200518165714-d020e156310a h1:9VFe4R5FRCUyidB1rdm3XdCRVuD/75P7Y4PtzEGhEE4=
github.com/cockroachdb/apd/v2 v2.0.3-0.20200518165714-d020e156310a/go.mod h1:DDxRlzC2lo3/vSlmSoS7JkqbbrARPuFOGr0B9pvN3Gw=
github.com/cockroachdb/apd/v3 v3.2.3 h1:4Zx+I3R35bFXMnltzmjP79i2cravE4jTRL6ps9Aux80=
github.com/cockroachdb/apd/v3 v3.2.3/go.mod h1:klXJcjp+FffLTHlhIG69tezTDvdP065naDsHzKhYSqc=
github.com/cockroachdb/datadriven v1.0.0/go.mod h1:5Ib8Meh+jk1RlHIXej6Pzevx/NLlNvQB9pmSBZErGA4=
github.com/cockroachdb/errors v1.6.1/go.mod h1:tm6FTP5G81vwJ5lC0SizQo374JNCOPrHyXGitRJoDqM=
github.com/cockroachdb/errors v1.7.5 h1:ptyO1BLW+sBxwBTSKJfS6kGzYCVKhI7MyBhoXAnPIKM=
Expand Down Expand Up @@ -255,8 +255,8 @@ github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U=
github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0=
github.com/dolthub/go-icu-regex v0.0.0-20260412212219-49724d547866 h1:U6gSf5I0e6h6GP1/5Sa7D2lWW1CWfcVPtY5wkyHq6jY=
github.com/dolthub/go-icu-regex v0.0.0-20260412212219-49724d547866/go.mod h1:F3cnm+vMRK1HaU6+rNqQrOCyR03HHhR1GWG2gnPOqaE=
github.com/dolthub/go-mysql-server v0.20.1-0.20260424221156-62a3b12d1f59 h1:rLs9hbZmhQ3G2myEL9VzKpY9E08s/tOLxvL6FvUxdB4=
github.com/dolthub/go-mysql-server v0.20.1-0.20260424221156-62a3b12d1f59/go.mod h1:O43PPQxMeNi7O5idizj6Itf2TZcSYfI/0WU24xhXg4I=
github.com/dolthub/go-mysql-server v0.20.1-0.20260427164548-6bc0cfa4e92a h1:l5b092QxSRIrWey7P7KhhEVfyuQUY8AqfIokKJuAHQQ=
github.com/dolthub/go-mysql-server v0.20.1-0.20260427164548-6bc0cfa4e92a/go.mod h1:XFCNmCSCXcQ6KNZr/FHoERkYpgMEMyIs9CTGSsiXRz4=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q=
github.com/dolthub/ishell v0.0.0-20260414231531-5f031e3e9037 h1:oIW9HwuWrhxv+4HZxA+QQSKHLqWFyXZ2FmNjUYwkdiM=
Expand Down Expand Up @@ -670,7 +670,6 @@ github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTw
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
2 changes: 1 addition & 1 deletion postgres/parser/encoding/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"math/big"
"unsafe"

"github.com/cockroachdb/apd/v2"
"github.com/cockroachdb/apd/v3"
"github.com/cockroachdb/errors"
)

Expand Down
2 changes: 1 addition & 1 deletion postgres/parser/encoding/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"fmt"
"unsafe"

"github.com/cockroachdb/apd/v2"
"github.com/cockroachdb/apd/v3"
"github.com/cockroachdb/errors"

"github.com/dolthub/doltgresql/postgres/parser/uuid"
Expand Down
2 changes: 1 addition & 1 deletion postgres/parser/json/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
package json

import (
"github.com/cockroachdb/apd/v2"
"github.com/cockroachdb/apd/v3"
"github.com/cockroachdb/errors"

"github.com/dolthub/doltgresql/postgres/parser/encoding"
Expand Down
2 changes: 1 addition & 1 deletion postgres/parser/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"unicode/utf8"
"unsafe"

"github.com/cockroachdb/apd/v2"
"github.com/cockroachdb/apd/v3"
"github.com/cockroachdb/errors"

"github.com/dolthub/doltgresql/postgres/parser/encoding"
Expand Down
4 changes: 2 additions & 2 deletions postgres/parser/sem/tree/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"unicode"
"unsafe"

"github.com/cockroachdb/apd/v2"
"github.com/cockroachdb/apd/v3"
"github.com/cockroachdb/errors"
"github.com/lib/pq/oid"

Expand Down Expand Up @@ -563,7 +563,7 @@ func (d *DDecimal) IsComposite() bool {

// Check if d is divisible by 10.
var r big.Int
r.Rem(&d.Decimal.Coeff, bigTen)
r.Rem((&d.Decimal.Coeff).MathBigInt(), bigTen)
return r.Sign() == 0
}

Expand Down
2 changes: 1 addition & 1 deletion postgres/parser/sem/tree/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"fmt"
"math"

"github.com/cockroachdb/apd/v2"
"github.com/cockroachdb/apd/v3"

"github.com/dolthub/doltgresql/postgres/parser/pgcode"
"github.com/dolthub/doltgresql/postgres/parser/pgerror"
Expand Down
3 changes: 2 additions & 1 deletion server/analyzer/type_sanitizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"strings"
"time"

"github.com/cockroachdb/apd/v3"
"github.com/cockroachdb/errors"
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/analyzer"
Expand Down Expand Up @@ -177,7 +178,7 @@ func typeSanitizerLiterals(ctx *sql.Context, gmsLiteral *expression.Literal) (sq
if !ok {
return nil, transform.NewTree, errors.Errorf("SANITIZER: expected decimal type: %T", gmsLiteral.Value())
}
return pgexprs.NewRawLiteralNumeric(dec), transform.NewTree, nil
return pgexprs.NewRawLiteralNumeric(*apd.New(dec.Coefficient().Int64(), dec.Exponent())), transform.NewTree, nil
case query.Type_DATE, query.Type_DATETIME, query.Type_TIMESTAMP:
newVal, _, err := types.Datetime.Convert(ctx, gmsLiteral.Value())
if err != nil {
Expand Down
10 changes: 1 addition & 9 deletions server/ast/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/cockroachdb/errors"
"github.com/dolthub/go-mysql-server/sql/expression"
vitess "github.com/dolthub/vitess/go/vt/sqlparser"
"github.com/shopspring/decimal"
"github.com/sirupsen/logrus"

"github.com/dolthub/doltgresql/core/id"
Expand Down Expand Up @@ -518,15 +517,8 @@ func nodeExpr(ctx *Context, node tree.Expr) (vitess.Expr, error) {
Expression: pgexprs.NewRawLiteralDate(t),
}, nil
case *tree.DDecimal:
// TODO: should we use apd.Decimal for Numeric type values?
// |Coeff| is always positive, so need to |Negative| to negate the big.Int
bigInt := &node.Coeff
if node.Negative {
bigInt = bigInt.Neg(bigInt)
}
return vitess.InjectedExpr{
Expression: pgexprs.NewRawLiteralNumeric(decimal.NewFromBigInt(bigInt, node.Exponent)),
}, nil
Expression: pgexprs.NewRawLiteralNumeric(node.Decimal)}, nil
case *tree.DEnum:
return nil, errors.Errorf("the statement is not yet supported")
case *tree.DFloat:
Expand Down
9 changes: 7 additions & 2 deletions server/cast/float32.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ package cast
import (
"math"

"github.com/cockroachdb/apd/v3"
"github.com/cockroachdb/errors"
"github.com/dolthub/go-mysql-server/sql"
"github.com/shopspring/decimal"

"github.com/dolthub/doltgresql/server/functions/framework"
pgtypes "github.com/dolthub/doltgresql/server/types"
Expand Down Expand Up @@ -70,7 +70,12 @@ func float32Assignment() {
FromType: pgtypes.Float32,
ToType: pgtypes.Numeric,
Function: func(ctx *sql.Context, val any, targetType *pgtypes.DoltgresType) (any, error) {
return pgtypes.GetNumericValueWithTypmod(decimal.NewFromFloat(float64(val.(float32))), targetType.GetAttTypMod())
d := new(apd.Decimal)
err := d.Scan(float64(val.(float32)))
if err != nil {
return nil, err
}
return pgtypes.GetNumericValueWithTypmod(*d, targetType.GetAttTypMod())
},
})
}
Expand Down
10 changes: 8 additions & 2 deletions server/cast/float64.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import (
"math"

"github.com/cockroachdb/apd/v3"
"github.com/cockroachdb/errors"
"github.com/dolthub/go-mysql-server/sql"
"github.com/shopspring/decimal"

"github.com/dolthub/doltgresql/server/functions/framework"
pgtypes "github.com/dolthub/doltgresql/server/types"
Expand Down Expand Up @@ -76,7 +76,13 @@
FromType: pgtypes.Float64,
ToType: pgtypes.Numeric,
Function: func(ctx *sql.Context, val any, targetType *pgtypes.DoltgresType) (any, error) {
return pgtypes.GetNumericValueWithTypmod(decimal.NewFromFloat(val.(float64)), targetType.GetAttTypMod())
d := new(apd.Decimal)
d.String()

Check failure on line 80 in server/cast/float64.go

View workflow job for this annotation

GitHub Actions / Verify format

result of (*github.com/cockroachdb/apd/v3.Decimal).String call not used
err := d.Scan(val.(float64))
if err != nil {
return nil, err
}
return pgtypes.GetNumericValueWithTypmod(*d, targetType.GetAttTypMod())
},
})
}
4 changes: 2 additions & 2 deletions server/cast/int16.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
package cast

import (
"github.com/cockroachdb/apd/v3"
"github.com/dolthub/go-mysql-server/sql"
"github.com/shopspring/decimal"

"github.com/dolthub/doltgresql/core/id"
"github.com/dolthub/doltgresql/server/functions/framework"
Expand Down Expand Up @@ -62,7 +62,7 @@ func int16Implicit() {
FromType: pgtypes.Int16,
ToType: pgtypes.Numeric,
Function: func(ctx *sql.Context, val any, targetType *pgtypes.DoltgresType) (any, error) {
return decimal.NewFromInt(int64(val.(int16))), nil
return pgtypes.GetNumericValueWithTypmod(*apd.New(int64(val.(int16)), 0), targetType.GetAttTypMod())
},
})
framework.MustAddImplicitTypeCast(framework.TypeCast{
Expand Down
4 changes: 2 additions & 2 deletions server/cast/int32.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
package cast

import (
"github.com/cockroachdb/apd/v3"
"github.com/cockroachdb/errors"

"github.com/dolthub/go-mysql-server/sql"
"github.com/shopspring/decimal"

"github.com/dolthub/doltgresql/core/id"
"github.com/dolthub/doltgresql/server/functions/framework"
Expand Down Expand Up @@ -84,7 +84,7 @@ func int32Implicit() {
FromType: pgtypes.Int32,
ToType: pgtypes.Numeric,
Function: func(ctx *sql.Context, val any, targetType *pgtypes.DoltgresType) (any, error) {
return decimal.NewFromInt(int64(val.(int32))), nil
return pgtypes.GetNumericValueWithTypmod(*apd.New(int64(val.(int32)), 0), targetType.GetAttTypMod())
},
})
framework.MustAddImplicitTypeCast(framework.TypeCast{
Expand Down
4 changes: 2 additions & 2 deletions server/cast/int64.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
package cast

import (
"github.com/cockroachdb/apd/v3"
"github.com/cockroachdb/errors"

"github.com/dolthub/go-mysql-server/sql"
"github.com/shopspring/decimal"

"github.com/dolthub/doltgresql/core/id"
"github.com/dolthub/doltgresql/server/functions/framework"
Expand Down Expand Up @@ -75,7 +75,7 @@ func int64Implicit() {
FromType: pgtypes.Int64,
ToType: pgtypes.Numeric,
Function: func(ctx *sql.Context, val any, targetType *pgtypes.DoltgresType) (any, error) {
return decimal.NewFromInt(val.(int64)), nil
return pgtypes.GetNumericValueWithTypmod(*apd.New(val.(int64), 0), targetType.GetAttTypMod())
},
})
framework.MustAddImplicitTypeCast(framework.TypeCast{
Expand Down
40 changes: 27 additions & 13 deletions server/cast/jsonb.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
package cast

import (
"github.com/cockroachdb/apd/v3"
"github.com/cockroachdb/errors"

"github.com/dolthub/go-mysql-server/sql"
"github.com/shopspring/decimal"

"github.com/dolthub/doltgresql/server/functions/framework"
pgtypes "github.com/dolthub/doltgresql/server/types"
Expand Down Expand Up @@ -66,7 +66,8 @@ func jsonbExplicit() {
case pgtypes.JsonValueString:
return nil, errors.Errorf("cannot cast jsonb string to type %s", targetType.String())
case pgtypes.JsonValueNumber:
f, _ := decimal.Decimal(value).Float64()
d := apd.Decimal(value)
f, _ := d.Float64()
return float32(f), nil
case pgtypes.JsonValueBoolean:
return nil, errors.Errorf("cannot cast jsonb boolean to type %s", targetType.String())
Expand All @@ -89,7 +90,8 @@ func jsonbExplicit() {
case pgtypes.JsonValueString:
return nil, errors.Errorf("cannot cast jsonb string to type %s", targetType.String())
case pgtypes.JsonValueNumber:
f, _ := decimal.Decimal(value).Float64()
d := apd.Decimal(value)
f, _ := d.Float64()
return f, nil
case pgtypes.JsonValueBoolean:
return nil, errors.Errorf("cannot cast jsonb boolean to type %s", targetType.String())
Expand All @@ -112,11 +114,15 @@ func jsonbExplicit() {
case pgtypes.JsonValueString:
return nil, errors.Errorf("cannot cast jsonb string to type %s", targetType.String())
case pgtypes.JsonValueNumber:
d := decimal.Decimal(value)
if d.LessThan(pgtypes.NumericValueMinInt16) || d.GreaterThan(pgtypes.NumericValueMaxInt16) {
d := apd.Decimal(value)
if d.Cmp(pgtypes.NumericValueMinInt16) < 0 || d.Cmp(pgtypes.NumericValueMaxInt16) > 0 {
return nil, errors.Errorf("smallint out of range")
}
return int16(d.IntPart()), nil
i, err := d.Int64()
if err != nil {
return nil, err
}
return int16(i), nil
case pgtypes.JsonValueBoolean:
return nil, errors.Errorf("cannot cast jsonb boolean to type %s", targetType.String())
case pgtypes.JsonValueNull:
Expand All @@ -138,11 +144,15 @@ func jsonbExplicit() {
case pgtypes.JsonValueString:
return nil, errors.Errorf("cannot cast jsonb string to type %s", targetType.String())
case pgtypes.JsonValueNumber:
d := decimal.Decimal(value)
if d.LessThan(pgtypes.NumericValueMinInt32) || d.GreaterThan(pgtypes.NumericValueMaxInt32) {
d := apd.Decimal(value)
if d.Cmp(pgtypes.NumericValueMinInt32) < 0 || d.Cmp(pgtypes.NumericValueMaxInt32) > 0 {
return nil, errors.Errorf("integer out of range")
}
return int32(d.IntPart()), nil
i, err := d.Int64()
if err != nil {
return nil, err
}
return int32(i), nil
case pgtypes.JsonValueBoolean:
return nil, errors.Errorf("cannot cast jsonb boolean to type %s", targetType.String())
case pgtypes.JsonValueNull:
Expand All @@ -164,11 +174,15 @@ func jsonbExplicit() {
case pgtypes.JsonValueString:
return nil, errors.Errorf("cannot cast jsonb string to type %s", targetType.String())
case pgtypes.JsonValueNumber:
d := decimal.Decimal(value)
if d.LessThan(pgtypes.NumericValueMinInt64) || d.GreaterThan(pgtypes.NumericValueMaxInt64) {
d := apd.Decimal(value)
if d.Cmp(pgtypes.NumericValueMinInt64) < 0 || d.Cmp(pgtypes.NumericValueMaxInt64) > 0 {
return nil, errors.Errorf("bigint out of range")
}
return int64(d.IntPart()), nil
i, err := d.Int64()
if err != nil {
return nil, err
}
return int64(i), nil
case pgtypes.JsonValueBoolean:
return nil, errors.Errorf("cannot cast jsonb boolean to type %s", targetType.String())
case pgtypes.JsonValueNull:
Expand All @@ -190,7 +204,7 @@ func jsonbExplicit() {
case pgtypes.JsonValueString:
return nil, errors.Errorf("cannot cast jsonb string to type %s", targetType.String())
case pgtypes.JsonValueNumber:
return decimal.Decimal(value), nil
return apd.Decimal(value), nil
case pgtypes.JsonValueBoolean:
return nil, errors.Errorf("cannot cast jsonb boolean to type %s", targetType.String())
case pgtypes.JsonValueNull:
Expand Down
Loading
Loading