From 33c1d9e66375edebb716333b794d1e84e5c67f81 Mon Sep 17 00:00:00 2001 From: go-jet Date: Tue, 4 Mar 2025 19:57:42 +0100 Subject: [PATCH] Reintroduce Uint64 literal constructor for postgres dialect. --- cmd/jet/version.go | 2 +- postgres/literal.go | 5 +++++ postgres/literal_test.go | 5 +++++ tests/postgres/alltypes_test.go | 13 +++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/cmd/jet/version.go b/cmd/jet/version.go index 3300008..f5371e4 100644 --- a/cmd/jet/version.go +++ b/cmd/jet/version.go @@ -1,3 +1,3 @@ package main -const version = "v2.11.1" +const version = "v2.12.0" diff --git a/postgres/literal.go b/postgres/literal.go index 4f1c2c8..d070c77 100644 --- a/postgres/literal.go +++ b/postgres/literal.go @@ -49,6 +49,11 @@ func Uint32(value uint32) IntegerExpression { return CAST(jet.Uint32(value)).AS_BIGINT() } +// Uint64 is constructor for 64 bit unsigned integer expressions literals. +func Uint64(value uint64) IntegerExpression { + return CAST(jet.Uint64(value)).AS_BIGINT() +} + // Float creates new float literal expression var Float = jet.Float diff --git a/postgres/literal_test.go b/postgres/literal_test.go index 7147573..b788098 100644 --- a/postgres/literal_test.go +++ b/postgres/literal_test.go @@ -49,6 +49,11 @@ func TestUint32(t *testing.T) { assertSerialize(t, Uint32(val), `$1::bigint`, val) } +func TestUint64(t *testing.T) { + val := uint32(math.MaxUint32) + assertSerialize(t, Uint32(val), `$1::bigint`, val) +} + func TestFloat(t *testing.T) { assertSerialize(t, Float(12.34), `$1`, float64(12.34)) diff --git a/tests/postgres/alltypes_test.go b/tests/postgres/alltypes_test.go index 6c3755a..e720e24 100644 --- a/tests/postgres/alltypes_test.go +++ b/tests/postgres/alltypes_test.go @@ -3,6 +3,7 @@ package postgres import ( "github.com/go-jet/jet/v2/internal/utils/ptr" "github.com/stretchr/testify/assert" + "math" "github.com/go-jet/jet/v2/qrm" "testing" @@ -715,6 +716,18 @@ LIMIT $38; testutils.AssertJSONFile(t, dest, "./testdata/results/common/float_operators.json") } +func TestUInt64Overflow(t *testing.T) { + stmt := AllTypes.INSERT(AllTypes.BigInt). + VALUES(Uint64(math.MaxUint64)) + + _, err := stmt.Exec(db) + if isPgxDriver() { + require.ErrorContains(t, err, "18446744073709551615 is greater than maximum value for Int8") + } else { + require.ErrorContains(t, err, "sql: converting argument $1 type: uint64 values with high bit set are not supported") + } +} + func TestIntegerOperators(t *testing.T) { skipForCockroachDB(t) // some functions are still unimplemented