Add the appropriate SQL type representation for floats in Postgres arrays.

Note that there is a separate problem with loading arrays of floats.

Original pull request #1037
See #1046
This commit is contained in:
Jens Schauder
2021-09-13 13:11:01 +02:00
committed by Mark Paluch
parent bc0d307415
commit 933b2f125d
5 changed files with 54 additions and 1 deletions

View File

@@ -38,7 +38,15 @@ public class JdbcPostgresDialect extends PostgresDialect implements JdbcDialect
static class JdbcPostgresArrayColumns extends PostgresArrayColumns implements JdbcArrayColumns {
@Override
public String getSqlTypeRepresentation(JDBCType jdbcType) {
return jdbcType == JDBCType.DOUBLE ? "FLOAT8" : jdbcType.getName();
if (jdbcType == JDBCType.DOUBLE) {
return "FLOAT8";
}
if (jdbcType == JDBCType.REAL) {
return "FLOAT4";
}
return jdbcType.getName();
}
}
}

View File

@@ -573,6 +573,25 @@ public class JdbcAggregateTemplateIntegrationTests {
assertThat(reloaded.digits).isEqualTo(Arrays.asList(1.2, 1.3, 1.4));
}
@Test // GH-1033
@EnabledOnFeature(SUPPORTS_ARRAYS)
public void saveAndLoadAnEntityWithListOfFloat() {
FloatListOwner floatListOwner = new FloatListOwner();
final List<Float> values = Arrays.asList(1.2f, 1.3f, 1.4f);
floatListOwner.digits.addAll(values);
FloatListOwner saved = template.save(floatListOwner);
assertThat(saved.id).isNotNull();
FloatListOwner reloaded = template.findById(saved.id, FloatListOwner.class);
assertThat(reloaded).isNotNull();
assertThat(reloaded.id).isEqualTo(saved.id);
}
@Test // DATAJDBC-259
@EnabledOnFeature(SUPPORTS_ARRAYS)
public void saveAndLoadAnEntityWithSet() {
@@ -929,6 +948,7 @@ public class JdbcAggregateTemplateIntegrationTests {
List<String> digits = new ArrayList<>();
}
@Table("ARRAY_OWNER")
private static class SetOwner {
@Id Long id;
@@ -943,6 +963,13 @@ public class JdbcAggregateTemplateIntegrationTests {
List<Double> digits = new ArrayList<>();
}
private static class FloatListOwner {
@Id Long id;
List<Float> digits = new ArrayList<>();
}
@Data
static class LegoSet {

View File

@@ -58,6 +58,12 @@ CREATE TABLE DOUBLE_LIST_OWNER
DIGITS ARRAY[10]
);
CREATE TABLE FLOAT_LIST_OWNER
(
ID SERIAL PRIMARY KEY,
DIGITS ARRAY[10]
);
CREATE TABLE CHAIN4
(
FOUR SERIAL PRIMARY KEY,

View File

@@ -60,6 +60,12 @@ CREATE TABLE DOUBLE_LIST_OWNER
DIGITS DOUBLE PRECISION ARRAY[10]
);
CREATE TABLE FLOAT_LIST_OWNER
(
ID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY,
DIGITS FLOAT ARRAY[10]
);
CREATE TABLE CHAIN4
(
FOUR BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 40) PRIMARY KEY,

View File

@@ -67,6 +67,12 @@ CREATE TABLE DOUBLE_LIST_OWNER
DIGITS DOUBLE PRECISION[10]
);
CREATE TABLE FLOAT_LIST_OWNER
(
ID SERIAL PRIMARY KEY,
DIGITS FLOAT[10]
);
CREATE TABLE BYTE_ARRAY_OWNER
(
ID SERIAL PRIMARY KEY,