Created
December 17, 2020 12:30
-
-
Save seut/275e734c66b3f6b02d4e1cf9df5233ef to your computer and use it in GitHub Desktop.
PgJDBC numeric binary test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@TestLogging("io.crate.action.sql:TRACE") | |
@Test | |
public void test_numeric_type() throws Exception { | |
properties.setProperty(PGProperty.BINARY_TRANSFER_ENABLE.getName(), "1700"); | |
try (Connection conn = DriverManager.getConnection(url(RW), properties)) { | |
conn.createStatement().executeUpdate( | |
"CREATE TABLE t (" + | |
" l bigint" + | |
") " + | |
"WITH (number_of_replicas = 0)"); | |
PreparedStatement preparedStatement = conn.prepareStatement( | |
"INSERT INTO t (l) VALUES (?), (?)"); | |
preparedStatement.setLong(1, Long.MAX_VALUE); | |
preparedStatement.setLong(2, 10L); | |
preparedStatement.executeUpdate(); | |
conn.createStatement().execute("REFRESH TABLE t"); | |
ResultSet rs = conn.createStatement().executeQuery("SELECT sum(l::numeric) as bd FROM t"); | |
assertThat(rs.next(), is(true)); | |
assertThat(rs.getBigDecimal("bd"), is(new BigDecimal(Long.MAX_VALUE).add(new BigDecimal(10L)))); | |
//rs = conn.createStatement().executeQuery("SELECT (12.12::numeric(4, 2) + 10.14::numeric(4, 2))::numeric(3,1) as bd"); | |
rs = conn.createStatement().executeQuery("SELECT 12345.1::numeric(6, 1) as bd"); | |
assertThat(rs.next(), is(true)); | |
//assertThat(rs.getBigDecimal("bd"), is(new BigDecimal("12.1").add(new BigDecimal("10.1")))); | |
assertThat(rs.getBigDecimal("bd"), is(new BigDecimal("1234.0"))); | |
} catch (BatchUpdateException e) { | |
throw e.getNextException(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment