Select to view content in your preferred language

Create New Field Issues -- Specify LONG creates DOUBLE

161
6
Jump to solution
Thursday
kapalczynski
Frequent Contributor

I am trying to create a new field in an Enterprise GDB ... 

I use the below and for some reason it creates the field with DOUBLE, 38, 8

arcpy.management.AddField(toFeatureClass, "LOCALITY", "LONG", 20, "", "", "Locality", "NULLABLE", "NON_REQUIRED")

 

kapalczynski_0-1736448616759.png

 

0 Kudos
1 Solution

Accepted Solutions
DavidSolari
MVP Regular Contributor

I have a feeling specifying a field length is tripping it up. This is what Pro spits out as a default Python command for adding a "Long" field, you should be able to tweak this:

arcpy.management.AddField(
    in_table=toFeatureClass,
    field_name="LOCALITY",
    field_type="LONG",
    field_precision=None,
    field_scale=None,
    field_length=None,
    field_alias="Locality",
    field_is_nullable="NULLABLE",
    field_is_required="NON_REQUIRED",
    field_domain=""
)

View solution in original post

6 Replies
DavidSolari
MVP Regular Contributor

I have a feeling specifying a field length is tripping it up. This is what Pro spits out as a default Python command for adding a "Long" field, you should be able to tweak this:

arcpy.management.AddField(
    in_table=toFeatureClass,
    field_name="LOCALITY",
    field_type="LONG",
    field_precision=None,
    field_scale=None,
    field_length=None,
    field_alias="Locality",
    field_is_nullable="NULLABLE",
    field_is_required="NON_REQUIRED",
    field_domain=""
)
kapalczynski
Frequent Contributor

As I needed 15 digits I had to create a DOULBE with 15 digits and 0 decimal places as LONG only holds 10 digits.

 

Laura
by MVP Regular Contributor
MVP Regular Contributor

Long field type I believe doesn't have precision or scale like (double or float) so the 20 would be ignored. Can you try without that?

arcpy.management.AddField(toFeatureClass, "LOCALITY", "LONG", "", "", "", "Locality", "NULLABLE", "NON_REQUIRED")

 

CodyPatterson
MVP Regular Contributor

Hey @kapalczynski 

It appears that the long will be created as a double if the precision is 11 or more from this documentation here:

https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/add-field.htm

For a field with a scale of 0, use a long or short integer field type. When creating a long integer field, specify a precision of 10 or less, or the field may be created as a double.

Cody

kapalczynski
Frequent Contributor

Thank you all for your comments... 

So if I need the field to carry 15 digits I have to make it a DOUBLE with PRECISION of 15 and no DECIMALS?

0 Kudos
TonyAlmeida
MVP Regular Contributor

You must use Double.

 

arcpy.management.AddField(
    in_table=toFeatureClass, 
    field_name="LOCALITY", 
    field_type="DOUBLE",  # Use DOUBLE for high-precision numbers
    field_precision=15,   # Total number of digits
    field_scale=0,        # No decimal places
    field_alias="Locality", 
    field_is_nullable="NULLABLE", 
    field_is_required="NON_REQUIRED"
)