diff --git a/postgres/literal.go b/postgres/literal.go index e23ee9c1..4f1c2c87 100644 --- a/postgres/literal.go +++ b/postgres/literal.go @@ -34,6 +34,21 @@ func Int64(value int64) IntegerExpression { return CAST(jet.Int(value)).AS_BIGINT() } +// Uint8 is constructor for 8 bit unsigned integer expressions literals. +func Uint8(value uint8) IntegerExpression { + return CAST(jet.Uint8(value)).AS_SMALLINT() +} + +// Uint16 is constructor for 16 bit unsigned integer expressions literals. +func Uint16(value uint16) IntegerExpression { + return CAST(jet.Uint16(value)).AS_INTEGER() +} + +// Uint32 is constructor for 32 bit unsigned integer expressions literals. +func Uint32(value uint32) IntegerExpression { + return CAST(jet.Uint32(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 a50ea8fd..7147573c 100644 --- a/postgres/literal_test.go +++ b/postgres/literal_test.go @@ -34,6 +34,21 @@ func TestInt64(t *testing.T) { assertSerialize(t, Int64(val), `$1::bigint`, val) } +func TestUint8(t *testing.T) { + val := uint8(math.MaxUint8) + assertSerialize(t, Uint8(val), `$1::smallint`, val) +} + +func TestUint16(t *testing.T) { + val := uint16(math.MaxUint16) + assertSerialize(t, Uint16(val), `$1::integer`, val) +} + +func TestUint32(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))