Add PostgreSQL-specific character type constructors: Text, Char, and VarChar.
This commit is contained in:
parent
4f0832b0e7
commit
2183af42f4
10 changed files with 152 additions and 144 deletions
|
|
@ -462,15 +462,15 @@ func TestStringOperators(t *testing.T) {
|
|||
|
||||
query := AllTypes.SELECT(
|
||||
AllTypes.Text.EQ(AllTypes.Char),
|
||||
AllTypes.Text.EQ(String("Text")),
|
||||
AllTypes.Text.EQ(Text("Text")),
|
||||
AllTypes.Text.NOT_EQ(AllTypes.VarCharPtr),
|
||||
AllTypes.Text.NOT_EQ(String("Text")),
|
||||
AllTypes.Text.NOT_EQ(Text("Text")),
|
||||
AllTypes.Text.GT(AllTypes.Text),
|
||||
AllTypes.Text.GT(String("Text")),
|
||||
AllTypes.Text.GT(Text("Text")),
|
||||
AllTypes.Text.GT_EQ(AllTypes.TextPtr),
|
||||
AllTypes.Text.GT_EQ(String("Text")),
|
||||
AllTypes.Text.GT_EQ(Text("Text")),
|
||||
AllTypes.Text.LT(AllTypes.Char),
|
||||
AllTypes.Text.LT(String("Text")),
|
||||
AllTypes.Text.LT(Text("Text")),
|
||||
AllTypes.Text.LT_EQ(AllTypes.VarChar),
|
||||
AllTypes.Text.LT_EQ(String("Text")),
|
||||
AllTypes.Text.BETWEEN(String("min"), String("max")),
|
||||
|
|
@ -490,13 +490,13 @@ func TestStringOperators(t *testing.T) {
|
|||
OCTET_LENGTH(AllTypes.Text),
|
||||
OCTET_LENGTH(String("length")),
|
||||
LOWER(AllTypes.VarCharPtr),
|
||||
LOWER(String("length")),
|
||||
LOWER(Char(4)("length")),
|
||||
UPPER(AllTypes.Char),
|
||||
UPPER(String("upper")),
|
||||
UPPER(VarChar()("upper")),
|
||||
BTRIM(AllTypes.VarChar),
|
||||
BTRIM(String("btrim")),
|
||||
BTRIM(Char()("btrim")),
|
||||
BTRIM(AllTypes.VarChar, String("AA")),
|
||||
BTRIM(String("btrim"), String("AA")),
|
||||
BTRIM(VarChar(11)("btrim"), String("AA")),
|
||||
LTRIM(AllTypes.VarChar),
|
||||
LTRIM(String("ltrim")),
|
||||
LTRIM(AllTypes.VarChar, String("A")),
|
||||
|
|
@ -533,7 +533,7 @@ func TestStringOperators(t *testing.T) {
|
|||
TO_HEX(AllTypes.IntegerPtr),
|
||||
)
|
||||
|
||||
dest := []struct{}{}
|
||||
var dest []struct{}
|
||||
err := query.Query(db, &dest)
|
||||
|
||||
require.NoError(t, err)
|
||||
|
|
@ -630,9 +630,9 @@ func TestFloatOperators(t *testing.T) {
|
|||
AllTypes.Numeric.BETWEEN(Float(1.34), AllTypes.Decimal).AS("between"),
|
||||
AllTypes.Numeric.NOT_BETWEEN(AllTypes.Decimal.MUL(Float(3)), Float(100.12)).AS("not_between"),
|
||||
|
||||
TRUNC(AllTypes.Decimal.ADD(AllTypes.Decimal), Uint8(2)).AS("add1"),
|
||||
TRUNC(AllTypes.Decimal.ADD(AllTypes.Decimal), Int8(2)).AS("add1"),
|
||||
TRUNC(AllTypes.Decimal.ADD(Float(11.22)), Int8(2)).AS("add2"),
|
||||
TRUNC(AllTypes.Decimal.SUB(AllTypes.DecimalPtr), Uint16(2)).AS("sub1"),
|
||||
TRUNC(AllTypes.Decimal.SUB(AllTypes.DecimalPtr), Int32(2)).AS("sub1"),
|
||||
TRUNC(AllTypes.Decimal.SUB(Float(11.22)), Int16(2)).AS("sub2"),
|
||||
TRUNC(AllTypes.Decimal.MUL(AllTypes.DecimalPtr), Int16(2)).AS("mul1"),
|
||||
TRUNC(AllTypes.Decimal.MUL(Float(11.22)), Int32(2)).AS("mul2"),
|
||||
|
|
@ -736,13 +736,13 @@ func TestIntegerOperators(t *testing.T) {
|
|||
AllTypes.Integer.BETWEEN(Int(11), Int(200)).AS("between"),
|
||||
AllTypes.Integer.NOT_BETWEEN(Int(66), Int(77)).AS("not_between"),
|
||||
AllTypes.BigInt.LT(AllTypes.BigIntPtr).AS("lt1"),
|
||||
AllTypes.BigInt.LT(Uint8(65)).AS("lt2"),
|
||||
AllTypes.BigInt.LT(Int16(65)).AS("lt2"),
|
||||
AllTypes.BigInt.LT_EQ(AllTypes.BigIntPtr).AS("lte1"),
|
||||
AllTypes.BigInt.LT_EQ(Uint16(65)).AS("lte2"),
|
||||
AllTypes.BigInt.LT_EQ(Int32(65)).AS("lte2"),
|
||||
AllTypes.BigInt.GT(AllTypes.BigIntPtr).AS("gt1"),
|
||||
AllTypes.BigInt.GT(Uint32(65)).AS("gt2"),
|
||||
AllTypes.BigInt.GT(Int64(65)).AS("gt2"),
|
||||
AllTypes.BigInt.GT_EQ(AllTypes.BigIntPtr).AS("gte1"),
|
||||
AllTypes.BigInt.GT_EQ(Uint64(65)).AS("gte2"),
|
||||
AllTypes.BigInt.GT_EQ(Int64(65)).AS("gte2"),
|
||||
|
||||
AllTypes.BigInt.ADD(AllTypes.BigInt).AS("add1"),
|
||||
AllTypes.BigInt.ADD(Int(11)).AS("add2"),
|
||||
|
|
@ -1111,8 +1111,8 @@ func TestRowExpression(t *testing.T) {
|
|||
nowAddHour := time.Now().Add(time.Hour)
|
||||
|
||||
stmt := SELECT(
|
||||
ROW(Int32(1), Float32(11.22), String("john")).AS("row"),
|
||||
WRAP(Int64(1), Float64(11.22), String("john")).AS("wrap"),
|
||||
ROW(Int32(1), Real(11.22), Text("john")).AS("row"),
|
||||
WRAP(Int64(1), Double(11.22), VarChar(10)("john")).AS("wrap"),
|
||||
|
||||
ROW(Bool(false), DateT(now)).EQ(ROW(Bool(true), DateT(now))),
|
||||
WRAP(Bool(false), DateT(now)).NOT_EQ(WRAP(Bool(true), DateT(now))),
|
||||
|
|
@ -1131,7 +1131,7 @@ func TestRowExpression(t *testing.T) {
|
|||
|
||||
testutils.AssertStatementSql(t, stmt, `
|
||||
SELECT ROW($1::integer, $2::real, $3::text) AS "row",
|
||||
($4::bigint, $5::double precision, $6::text) AS "wrap",
|
||||
($4::bigint, $5::double precision, $6::varchar(10)) AS "wrap",
|
||||
ROW($7::boolean, $8::date) = ROW($9::boolean, $10::date),
|
||||
($11::boolean, $12::date) != ($13::boolean, $14::date),
|
||||
ROW($15::time without time zone) IS DISTINCT FROM (row(NOW()::time)),
|
||||
|
|
|
|||
|
|
@ -660,8 +660,8 @@ func TestSelectExecution1(t *testing.T) {
|
|||
).
|
||||
WHERE(
|
||||
OR(
|
||||
City.City.EQ(String("London")),
|
||||
City.City.EQ(String("York")),
|
||||
City.City.EQ(Text("London")),
|
||||
City.City.EQ(Text("York")),
|
||||
),
|
||||
).
|
||||
ORDER_BY(
|
||||
|
|
@ -741,7 +741,7 @@ func TestSelectExecution2(t *testing.T) {
|
|||
Customer.CustomerID.AS("my_customer.id"),
|
||||
Customer.LastName.AS("my_customer.last_name"),
|
||||
).
|
||||
WHERE(City.City.EQ(String("London")).OR(City.City.EQ(String("York")))).
|
||||
WHERE(City.City.EQ(VarChar()("London")).OR(City.City.EQ(VarChar()("York")))).
|
||||
ORDER_BY(City.CityID, Address.AddressID, Customer.CustomerID)
|
||||
|
||||
testutils.AssertDebugStatementSql(t, stmt, `
|
||||
|
|
@ -754,7 +754,7 @@ SELECT city.city_id AS "my_city.id",
|
|||
FROM dvds.city
|
||||
INNER JOIN dvds.address ON (address.city_id = city.city_id)
|
||||
INNER JOIN dvds.customer ON (customer.address_id = address.address_id)
|
||||
WHERE (city.city = 'London'::text) OR (city.city = 'York'::text)
|
||||
WHERE (city.city = 'London'::varchar) OR (city.city = 'York'::varchar)
|
||||
ORDER BY city.city_id, address.address_id, customer.customer_id;
|
||||
`, "London", "York")
|
||||
|
||||
|
|
@ -798,7 +798,7 @@ func TestSelectExecution3(t *testing.T) {
|
|||
Address.AddressID.AS("address_id"),
|
||||
Address.Address.AS("address_line"),
|
||||
).
|
||||
WHERE(City.City.EQ(String("London")).OR(City.City.EQ(String("York")))).
|
||||
WHERE(City.City.EQ(VarChar(20)("London")).OR(City.City.EQ(VarChar(20)("York")))).
|
||||
ORDER_BY(City.CityID, Address.AddressID, Customer.CustomerID)
|
||||
|
||||
testutils.AssertDebugStatementSql(t, stmt, `
|
||||
|
|
@ -811,7 +811,7 @@ SELECT city.city_id AS "city_id",
|
|||
FROM dvds.city
|
||||
INNER JOIN dvds.address ON (address.city_id = city.city_id)
|
||||
INNER JOIN dvds.customer ON (customer.address_id = address.address_id)
|
||||
WHERE (city.city = 'London'::text) OR (city.city = 'York'::text)
|
||||
WHERE (city.city = 'London'::varchar(20)) OR (city.city = 'York'::varchar(20))
|
||||
ORDER BY city.city_id, address.address_id, customer.customer_id;
|
||||
`, "London", "York")
|
||||
|
||||
|
|
@ -1866,7 +1866,7 @@ SELECT customer.customer_id AS "customer.customer_id",
|
|||
FROM dvds.payment
|
||||
INNER JOIN dvds.customer ON (customer.customer_id = payment.customer_id)
|
||||
GROUP BY customer.customer_id
|
||||
HAVING SUM(payment.amount) > 125.6
|
||||
HAVING SUM(payment.amount) > 125::real
|
||||
ORDER BY customer.customer_id, SUM(payment.amount) ASC;
|
||||
`
|
||||
query := SELECT(
|
||||
|
|
@ -1885,14 +1885,14 @@ ORDER BY customer.customer_id, SUM(payment.amount) ASC;
|
|||
).GROUP_BY(
|
||||
Customer.CustomerID,
|
||||
).HAVING(
|
||||
SUMf(Payment.Amount).GT(Float(125.6)),
|
||||
SUMf(Payment.Amount).GT(Real(125)),
|
||||
).ORDER_BY(
|
||||
Customer.CustomerID, SUMf(Payment.Amount).ASC(),
|
||||
)
|
||||
|
||||
//fmt.Println(query.DebugSql())
|
||||
|
||||
testutils.AssertDebugStatementSql(t, query, expectedSQL, float64(125.6))
|
||||
testutils.AssertDebugStatementSql(t, query, expectedSQL, float32(125))
|
||||
|
||||
var dest []struct {
|
||||
model.Customer
|
||||
|
|
@ -2378,14 +2378,14 @@ func TestSelectUnion(t *testing.T) {
|
|||
SELECT payment.payment_id AS "payment.payment_id",
|
||||
payment.amount AS "payment.amount"
|
||||
FROM dvds.payment
|
||||
WHERE payment.amount <= 100
|
||||
WHERE payment.amount <= 100::double precision
|
||||
)
|
||||
UNION ALL
|
||||
(
|
||||
SELECT payment.payment_id AS "payment.payment_id",
|
||||
payment.amount AS "payment.amount"
|
||||
FROM dvds.payment
|
||||
WHERE payment.amount >= 200
|
||||
WHERE payment.amount >= 200::double precision
|
||||
)
|
||||
ORDER BY "payment.payment_id" ASC, "payment.amount" DESC
|
||||
LIMIT 10
|
||||
|
|
@ -2394,10 +2394,10 @@ OFFSET 20;
|
|||
query := UNION_ALL(
|
||||
Payment.
|
||||
SELECT(Payment.PaymentID.AS("payment.payment_id"), Payment.Amount).
|
||||
WHERE(Payment.Amount.LT_EQ(Float(100))),
|
||||
WHERE(Payment.Amount.LT_EQ(Double(100))),
|
||||
Payment.
|
||||
SELECT(Payment.PaymentID, Payment.Amount).
|
||||
WHERE(Payment.Amount.GT_EQ(Float(200))),
|
||||
WHERE(Payment.Amount.GT_EQ(Double(200))),
|
||||
).ORDER_BY(
|
||||
IntegerColumn("payment.payment_id").ASC(),
|
||||
Payment.Amount.DESC(),
|
||||
|
|
@ -2729,7 +2729,7 @@ FROM dvds.actor
|
|||
INNER JOIN dvds.language ON (language.language_id = film.language_id)
|
||||
INNER JOIN dvds.film_category ON (film_category.film_id = film.film_id)
|
||||
INNER JOIN dvds.category ON (category.category_id = film_category.category_id)
|
||||
WHERE ((language.name = 'English'::text) AND (category.name != 'Action'::text)) AND (film.length > 180)
|
||||
WHERE ((language.name = 'English'::char(20)) AND (category.name != 'Action'::text)) AND (film.length > 180::integer)
|
||||
ORDER BY actor.actor_id ASC, film.film_id ASC;
|
||||
`
|
||||
|
||||
|
|
@ -2746,15 +2746,15 @@ ORDER BY actor.actor_id ASC, film.film_id ASC;
|
|||
INNER_JOIN(FilmCategory, FilmCategory.FilmID.EQ(Film.FilmID)).
|
||||
INNER_JOIN(Category, Category.CategoryID.EQ(FilmCategory.CategoryID)),
|
||||
).WHERE(
|
||||
Language.Name.EQ(String("English")). // note that every column has type.
|
||||
AND(Category.Name.NOT_EQ(String("Action"))). // String column Language.Name and Category.Name can be compared only with string expression
|
||||
AND(Film.Length.GT(Int(180))), // Film.Length is integer column and can be compared only with integer expression
|
||||
Language.Name.EQ(Char(20)("English")). // note that every column has type.
|
||||
AND(Category.Name.NOT_EQ(Text("Action"))). // String column Language.Name and Category.Name can be compared only with string expression
|
||||
AND(Film.Length.GT(Int32(180))), // Film.Length is integer column and can be compared only with integer expression
|
||||
).ORDER_BY(
|
||||
Actor.ActorID.ASC(),
|
||||
Film.FilmID.ASC(),
|
||||
)
|
||||
|
||||
testutils.AssertDebugStatementSql(t, stmt, expectedSQL, "English", "Action", int64(180))
|
||||
testutils.AssertDebugStatementSql(t, stmt, expectedSQL, "English", "Action", int32(180))
|
||||
|
||||
var dest []struct {
|
||||
model.Actor
|
||||
|
|
@ -3162,7 +3162,7 @@ func TestSelectLateral(t *testing.T) {
|
|||
).FROM(
|
||||
Language,
|
||||
).WHERE(
|
||||
Language.Name.NOT_IN(String("spanish")).
|
||||
Language.Name.NOT_IN(Char(20)("Spanish"), Char(20)("Catalan")).
|
||||
AND(Film.LanguageID.EQ(Language.LanguageID)),
|
||||
),
|
||||
).AS("films")
|
||||
|
|
@ -3191,7 +3191,7 @@ FROM dvds.film
|
|||
language.name AS "language.name",
|
||||
language.last_update AS "language.last_update"
|
||||
FROM dvds.language
|
||||
WHERE (language.name NOT IN ('spanish'::text)) AND (film.language_id = language.language_id)
|
||||
WHERE (language.name NOT IN ('Spanish'::char(20), 'Catalan'::char(20))) AND (film.language_id = language.language_id)
|
||||
) AS films
|
||||
WHERE film.film_id = 1
|
||||
ORDER BY film.film_id
|
||||
|
|
@ -3236,7 +3236,7 @@ FROM dvds.film,
|
|||
language.name AS "language.name",
|
||||
language.last_update AS "language.last_update"
|
||||
FROM dvds.language
|
||||
WHERE (language.name NOT IN ('spanish'::text)) AND (film.language_id = language.language_id)
|
||||
WHERE (language.name NOT IN ('Spanish'::char(20), 'Catalan'::char(20))) AND (film.language_id = language.language_id)
|
||||
) AS films
|
||||
WHERE film.film_id = 1
|
||||
ORDER BY film.film_id
|
||||
|
|
@ -3787,9 +3787,9 @@ func TestSelectConditionalFunctions(t *testing.T) {
|
|||
Film.SELECT(Film.FilmID).WHERE(Film.RentalDuration.GT(Int(100))),
|
||||
).AS("exists"),
|
||||
CASE(Film.Length.GT(Int(120))).
|
||||
WHEN(Bool(true)).THEN(String("long film")).
|
||||
ELSE(String("short film")).AS("case"),
|
||||
COALESCE(Film.Description, String("none")).AS("coalesce"),
|
||||
WHEN(Bool(true)).THEN(Text("long film")).
|
||||
ELSE(Text("short film")).AS("case"),
|
||||
COALESCE(Film.Description, Text("none")).AS("coalesce"),
|
||||
NULLIF(Film.ReleaseYear, Int(200)).AS("null_if"),
|
||||
GREATEST(Film.RentalDuration, Int(4), Int(5)).AS("greatest"),
|
||||
LEAST(Film.RentalDuration, Int(7), Int(6)).AS("least"),
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ import (
|
|||
func TestVALUES(t *testing.T) {
|
||||
|
||||
values := VALUES(
|
||||
WRAP(Int32(1), Int32(2), Float32(4.666), Bool(false), String("txt")),
|
||||
WRAP(Int32(11).ADD(Int32(2)), Int32(22), Float32(33.222), Bool(true), String("png")),
|
||||
WRAP(Int32(11), Int32(22), Float32(33.222), Bool(true), NULL),
|
||||
WRAP(Int32(1), Int32(2), Real(4.666), Bool(false), String("txt")),
|
||||
WRAP(Int32(11).ADD(Int32(2)), Int32(22), Real(33.222), Bool(true), String("png")),
|
||||
WRAP(Int32(11), Int32(22), Real(33.222), Bool(true), NULL),
|
||||
).AS("values_table")
|
||||
|
||||
stmt := SELECT(
|
||||
|
|
@ -86,11 +86,11 @@ func TestVALUES_Join(t *testing.T) {
|
|||
lastUpdate := Timestamp(2007, time.February, 11, 12, 0, 0)
|
||||
|
||||
filmValues := VALUES(
|
||||
WRAP(String("Chamber Italian"), Int64(117), Int32(2005), Float32(5.82), lastUpdate),
|
||||
WRAP(String("Grosse Wonderful"), Int64(49), Int32(2004), Float32(6.242), lastUpdate.ADD(INTERVAL(1, HOUR))),
|
||||
WRAP(String("Airport Pollock"), Int64(54), Int32(2001), Float32(7.22), NULL),
|
||||
WRAP(String("Bright Encounters"), Int64(73), Int32(2002), Float32(8.25), NULL),
|
||||
WRAP(String("Academy Dinosaur"), Int64(83), Int32(2010), Float32(9.22), lastUpdate.SUB(INTERVAL(2, MINUTE))),
|
||||
WRAP(String("Chamber Italian"), Int64(117), Int32(2005), Real(5.82), lastUpdate),
|
||||
WRAP(String("Grosse Wonderful"), Int64(49), Int32(2004), Real(6.242), lastUpdate.ADD(INTERVAL(1, HOUR))),
|
||||
WRAP(String("Airport Pollock"), Int64(54), Int32(2001), Real(7.22), NULL),
|
||||
WRAP(String("Bright Encounters"), Int64(73), Int32(2002), Real(8.25), NULL),
|
||||
WRAP(String("Academy Dinosaur"), Int64(83), Int32(2010), Real(9.22), lastUpdate.SUB(INTERVAL(2, MINUTE))),
|
||||
).AS("film_values",
|
||||
title, IntegerColumn("length"), releaseYear, rentalRate, TimestampColumn("update_date"))
|
||||
|
||||
|
|
@ -216,10 +216,10 @@ func TestVALUES_CTE_Update(t *testing.T) {
|
|||
stmt := WITH(
|
||||
paymentsToUpdate.AS(
|
||||
VALUES(
|
||||
WRAP(Int32(20564), Float32(1.21)),
|
||||
WRAP(Int32(20567), Float32(1.02)),
|
||||
WRAP(Int32(20570), Float32(1.34)),
|
||||
WRAP(Int32(20573), Float32(1.72)),
|
||||
WRAP(Int32(20564), Real(1.21)),
|
||||
WRAP(Int32(20567), Real(1.02)),
|
||||
WRAP(Int32(20570), Real(1.34)),
|
||||
WRAP(Int32(20573), Real(1.72)),
|
||||
),
|
||||
),
|
||||
)(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue