mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-24 15:55:55 +00:00
#700 - Postgres ARRAY and JSON expressions cast Long to ::integer rather than ::bigint
This commit is contained in:
@@ -24,29 +24,18 @@ public class PostgresCast {
|
||||
// for exists and not-exists expressions
|
||||
return "";
|
||||
}
|
||||
|
||||
if (isIntegerType(value)) {
|
||||
if (value instanceof Integer) {
|
||||
return asArray ? "::integer[]" : "::integer";
|
||||
}
|
||||
if (isNumberType(value)) {
|
||||
if (value instanceof Long) {
|
||||
return asArray ? "::bigint[]" : "::bigint";
|
||||
}
|
||||
if (value instanceof Number) {
|
||||
return asArray ? "::decimal[]" : "::decimal";
|
||||
}
|
||||
if (isBooleanType(value)) {
|
||||
if (value instanceof Boolean) {
|
||||
return asArray ? "::boolean[]" : "::boolean";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private static boolean isBooleanType(Object value) {
|
||||
return (value instanceof Boolean);
|
||||
}
|
||||
|
||||
private static boolean isIntegerType(Object value) {
|
||||
return (value instanceof Integer) || (value instanceof Long);
|
||||
}
|
||||
|
||||
private static boolean isNumberType(Object value) {
|
||||
return (value instanceof Number);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.avaje.ebeaninternal.server.core;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
public class PostgresCastTest {
|
||||
|
||||
@Test
|
||||
public void cast() throws Exception {
|
||||
|
||||
assertThat(PostgresCast.cast(1)).isEqualTo("::integer");
|
||||
assertThat(PostgresCast.cast(1L)).isEqualTo("::bigint");
|
||||
assertThat(PostgresCast.cast(1.0D)).isEqualTo("::decimal");
|
||||
assertThat(PostgresCast.cast("")).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cast1() throws Exception {
|
||||
|
||||
assertThat(PostgresCast.cast(1, true)).isEqualTo("::integer[]");
|
||||
assertThat(PostgresCast.cast(1L, true)).isEqualTo("::bigint[]");
|
||||
assertThat(PostgresCast.cast(1.0D, true)).isEqualTo("::decimal[]");
|
||||
assertThat(PostgresCast.cast("", true)).isEqualTo("");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user