Creating a table with NUMERIC(precision) results in error

Bug #870065 reported by Mike
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Stado
Fix Committed
Undecided
Unassigned

Bug Description

The following command results in an error:
lss=> create table blahfive (prim NUMERIC(20));
ERROR: NUMERIC scale -1 must be between 0 and precision 20

On further investigation it was discovered that what is actually passed to a node is the following:
2011-10-07 15:33:40 IST STATEMENT: CREATE TABLE "blahfive" ("prim" NUMERIC (20, -1))
2011-10-07 15:35:07 IST ERROR: NUMERIC scale -1 must be between 0 and precision 20 at character 33

The scale parameter is being passed as -1, which is invalid.

On further investigation, I created a new NUMERIC TEMPLATE called NUMERIC_TEMPLATE_WITHOUT_SCALE, which looks like this:
Index: src/org/postgresql/stado/parser/handler/TypeConstants.java
===================================================================
--- src/org/postgresql/stado/parser/handler/TypeConstants.java (revision 6482)
+++ src/org/postgresql/stado/parser/handler/TypeConstants.java (working copy)
@@ -61,6 +61,10 @@
     public static final String NUMERIC_TEMPLATE = Property.get(
             "xdb.sqltype.numeric.map", "NUMERIC ({precision}, {scale})");

+// mike debug added for case when precision is non-zero but scale not specified
+ public static final String NUMERIC_TEMPLATE_WITHOUT_SCALE = Property.get(
+ "xdb.sqltype.numeric.map", "NUMERIC ({precision})");
+
     public static final String NUMERIC_TEMPLATE_WITHOUT_PRECISION = Property.get(
             "xdb.sqltype.numeric.map", "NUMERIC");

This was added to the data type handler like so:

Index: src/org/postgresql/stado/parser/handler/DataTypeHandler.java
===================================================================
--- src/org/postgresql/stado/parser/handler/DataTypeHandler.java (revision 6482)
+++ src/org/postgresql/stado/parser/handler/DataTypeHandler.java (working copy)
@@ -796,10 +796,17 @@
             typeString = DOUBLE_TEMPLATE;
             break;
         case Types.NUMERIC:
- if (precision == -1) {
- typeString = NUMERIC_TEMPLATE_WITHOUT_PRECISION;
- } else {
- typeString = NUMERIC_TEMPLATE;
+ if (precision == -1)
+ {
+ typeString = NUMERIC_TEMPLATE_WITHOUT_PRECISION;
+ }
+ else if (scale == -1)
+ {
+ typeString = NUMERIC_TEMPLATE_WITHOUT_SCALE;
+ }
+ else
+ {
+ typeString = NUMERIC_TEMPLATE;
          }
             break;
         case Types.TIMESTAMP:

Hoping the above is correct, thought it might be useful to report.
Mike

Revision history for this message
Jim Mlodgenski (jim-cirrusql) wrote :

Thanks for the patch. I just committed it to the trunk.

Changed in stado:
status: New → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.