Add Field tool Precision/Scale issues

4842
5
06-26-2012 01:20 PM
MikeLouwrens
Occasional Contributor III
Hi,
  

  Using the AddField geoprocessing tool to create new fields on feature classes.  When the new field is a DOUBLE type field, I am setting field Precision and Scale.  However when the field is created, the Precision and Scale have been ignored.  I set Precision = 10 and Scale = 3, but when I look at the fields after I???ve run the AddField tool the Precision = 38 and Scale = 8.
  

  If I add a field in the feature class properties in Arc Catalog and set the Precision and Scale there, the field is set up correctly.  It???s only failing when I use the AddField tool. 

  
  Is there a way to get these created properly?  I need to script these to create a number of fields on a number of feature classes.
  
  The feature classes are in an SDE database (9.3.1 on SQL Server) and I???m creating them using ArcGIS 10 SP4.
  
  Cheers,
  Mike.
0 Kudos
5 Replies
KimOllivier
Occasional Contributor III
Try using a template when you define a featureclass with the fields correctly set manually in ArcCatalog. Not quite an AddField for an existing table, but maybe you can adapt your workflow somehow.

Or maybe use the SQL command ALTER TABLE in Python to add the fields yourself. Presumably that is all that AddField does in the background.
0 Kudos
DominickCisson
Occasional Contributor
A template is not really a great solution here.  If you're going to use a template, why not just create everything in ArcCatalog in the first place?  Why does this tool simply fail to take precision and scale into account when executed?  Is this a known bug?  If not, it's amazing this doesn't work and hasn't been noted before now.  I'm running into the same exact issue in ArcGIS 10.0 sp4 on SQL Server 2008 R2... it is quite maddening.
0 Kudos
DominickCisson
Occasional Contributor
OK this is straight from the AddField help file...

Part 1:



  • The precision and scale of a field describe the maximum size and precision of data that can be stored in the field. The precision describes the number of digits that can be stored in the field and the scale describes the number of decimal places for float and double fields. For example, if the field value is 54.234, then scale = 3 and precision = 5.


  • Use the following guidelines for choosing the correct field type for a given precision and scale:


  • When you create a float, double, or integer field and specify 0 for precision and scale, the tool will attempt to create a binary type field if the underlying database supports it. Personal and file geodatabases support only binary type fields, and precision and scale are ignored.

  • When you create float and double fields and specify a precision and scale, if your precision is greater than 6, use a double; otherwise, use a float. If you create a double field and specify a precision of 6 or less, a float field is created. If you create a float field and specify a precision greater than 6, a double field is created.

  • If you specify a scale of 0 and a precision of 10 or less, you should be creating integer fields. When creating integer fields, your precision should be 10 or less, or your field may be created as double.


Ok excellent right?  Now, here't the very next bullet...


  • When creating a new field in a geodatabase feature class or table, you can specify the field's type, but not its precision, and scale. Even if the dialog box allows you to add a value for precision or scale, it will be ignored during execution.



Wait, what?  Why would you provide a tool to define these paramaters, explain how to do so, show multiple examples in the help setting precision and scale ON FEATURE CLASSES, and then have a bullet point that says, oh by the way, precision and scale are ignored?

I notice there are no esri-provided smileys for banging one's head against a wall.  Probably because every other forum post would begin and end with one.
0 Kudos
MikeLouwrens
Occasional Contributor III
Yes, it turned out it was a bug.  Has been fixed in 10.1, but it hadn't been fixed in SP5 (I tested this before I installed 10.1)

I believe the reference in the help is referring to file/personal geodatabases and not SDE.

  • When creating a new field in a geodatabase feature class or table, you can specify the field's type, but not its precision, and scale. Even if the dialog box allows you to add a value for precision or scale, it will be ignored during execution.

So for me now the problem has gone (as I'm now using 10.1)

Cheers,
Mike.
0 Kudos
BrianaGarrison
New Contributor
I am also having the same issues listed here. 

I am calculating area on a raster field and converting to acres.  Using the Add Field function, I create a new field with a Prec of 10 and scale of 9 (to give myself plenty of room) and then 'Start Edits' > Field Calculator > [Count]*.222395

This gives me a variety of different numbers back.  One row will have interpreted it as [Count] *2.22395  and all the rows will only keep 4 significant digits before round all the rest to zeros.  This is a problem when estimating acres that are 10,000 and the last digit is still important to know.

Why is this calculation/process producing erratic results?
0 Kudos