Skip to content

Commit

Permalink
feat: optimized binary numeric support (#1940)
Browse files Browse the repository at this point in the history
Optimize support for the binary representation of the numeric data type.
  • Loading branch information
bokken committed Dec 30, 2020
1 parent 864facc commit 2c41ffc
Show file tree
Hide file tree
Showing 8 changed files with 672 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ public String toString(@Positive int index, boolean standardConformingStrings) {
}
return Double.toString(d);

case Oid.NUMERIC:
Number n = ByteConverter.numeric((byte[]) paramValue);
if (n instanceof Double) {
assert ((Double) n).isNaN();
return "'NaN'::numeric";
}
return n.toString();

case Oid.UUID:
String uuid =
new UUIDArrayAssistant().buildElement((byte[]) paramValue, 0, 16).toString();
Expand Down
1 change: 1 addition & 0 deletions pgjdbc/src/main/java/org/postgresql/jdbc/PgConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ private static Set<Integer> getSupportedBinaryOids() {
Oid.INT8,
Oid.FLOAT4,
Oid.FLOAT8,
Oid.NUMERIC,
Oid.TIME,
Oid.DATE,
Oid.TIMETZ,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@ public void setDouble(@Positive int parameterIndex, double x) throws SQLExceptio

public void setBigDecimal(@Positive int parameterIndex, @Nullable BigDecimal x)
throws SQLException {
if (x != null && connection.binaryTransferSend(Oid.NUMERIC)) {
final byte[] bytes = ByteConverter.numeric(x);
bindBytes(parameterIndex, bytes, Oid.NUMERIC);
return;
}
setNumber(parameterIndex, x);
}

Expand Down

0 comments on commit 2c41ffc

Please sign in to comment.