@@ -54,12 +54,27 @@ public ColDataType() {
5454 }
5555
5656 public ColDataType (String dataType , int precision , int scale ) {
57- this .dataType = dataType ;
57+ this (dataType );
58+ setNumericParameters (precision < 0 ? null : Integer .valueOf (precision ),
59+ scale < 0 ? null : Integer .valueOf (scale ));
60+ }
61+
62+ /**
63+ * Creates a parameterized type, using {@code null} for an omitted parameter. Unlike the legacy
64+ * primitive constructor, this accepts negative scales, including {@code -1}.
65+ */
66+ public static ColDataType fromNumericParameters (String dataType , Integer precision ,
67+ Integer scale ) {
68+ ColDataType type = new ColDataType (dataType );
69+ type .setNumericParameters (precision , scale );
70+ return type ;
71+ }
5872
59- if (precision >= 0 ) {
73+ private void setNumericParameters (Integer precision , Integer scale ) {
74+ if (precision != null ) {
6075 this .precision = precision ;
6176 this .dataType += " (" + (precision == Integer .MAX_VALUE ? "MAX" : precision );
62- if (scale >= 0 ) {
77+ if (scale != null ) {
6378 this .scale = scale ;
6479 this .dataType += ", " + scale ;
6580 }
@@ -211,8 +226,8 @@ public void setPrecision(Integer precision) {
211226 }
212227
213228 /**
214- * The second numeric type parameter, e.g. {@code 2} for {@code DECIMAL(10, 2)}. Returns
215- * {@code null} when absent.
229+ * The second numeric type parameter, e.g. {@code 2} for {@code DECIMAL(10, 2)} or {@code -3}
230+ * for PostgreSQL {@code NUMERIC(2, -3)}. Returns {@code null} when absent.
216231 */
217232 public Integer getScale () {
218233 return scale ;
0 commit comments