Skip to content

Commit 33c1d9e

Browse files
committed
Reintroduce Uint64 literal constructor for postgres dialect.
1 parent 7047de4 commit 33c1d9e

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

cmd/jet/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package main
22

3-
const version = "v2.11.1"
3+
const version = "v2.12.0"

postgres/literal.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ func Uint32(value uint32) IntegerExpression {
4949
return CAST(jet.Uint32(value)).AS_BIGINT()
5050
}
5151

52+
// Uint64 is constructor for 64 bit unsigned integer expressions literals.
53+
func Uint64(value uint64) IntegerExpression {
54+
return CAST(jet.Uint64(value)).AS_BIGINT()
55+
}
56+
5257
// Float creates new float literal expression
5358
var Float = jet.Float
5459

postgres/literal_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ func TestUint32(t *testing.T) {
4949
assertSerialize(t, Uint32(val), `$1::bigint`, val)
5050
}
5151

52+
func TestUint64(t *testing.T) {
53+
val := uint32(math.MaxUint32)
54+
assertSerialize(t, Uint32(val), `$1::bigint`, val)
55+
}
56+
5257
func TestFloat(t *testing.T) {
5358
assertSerialize(t, Float(12.34), `$1`, float64(12.34))
5459

tests/postgres/alltypes_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package postgres
33
import (
44
"github.com/go-jet/jet/v2/internal/utils/ptr"
55
"github.com/stretchr/testify/assert"
6+
"math"
67

78
"github.com/go-jet/jet/v2/qrm"
89
"testing"
@@ -715,6 +716,18 @@ LIMIT $38;
715716
testutils.AssertJSONFile(t, dest, "./testdata/results/common/float_operators.json")
716717
}
717718

719+
func TestUInt64Overflow(t *testing.T) {
720+
stmt := AllTypes.INSERT(AllTypes.BigInt).
721+
VALUES(Uint64(math.MaxUint64))
722+
723+
_, err := stmt.Exec(db)
724+
if isPgxDriver() {
725+
require.ErrorContains(t, err, "18446744073709551615 is greater than maximum value for Int8")
726+
} else {
727+
require.ErrorContains(t, err, "sql: converting argument $1 type: uint64 values with high bit set are not supported")
728+
}
729+
}
730+
718731
func TestIntegerOperators(t *testing.T) {
719732
skipForCockroachDB(t) // some functions are still unimplemented
720733

0 commit comments

Comments
 (0)