I have to make an SQL query on a column having not adequat name "type_borne_id", I couldn't make SQL queries using arcpy.Select_analysis neither selectbyattribute, but when I use select_analysis toolbox in arcmap it works with the same column.
I wonder if I should add some characters, or what to do, to query this column normally? I remarked that this pattern of names "name_column_id" is vulnerable to this error.
Example of the queries that didn't work:
arcpy.Select_analysis("table" , "table_copy" , " type_borne_id = 23" )
arcpy.Select_analysis("table" , "table_copy" , ' "type_borne_id" = 23' )
I have tested with other fields like "id" and it works normally.
I'm using Arcgis 10.1 & ArcSDE 10.1 on PostgreSQL.
2 Answers 2
All selections through arcpy needs to be quoted similarly to how you see them in ArcMap itself.
In ArcMap you would see something like:
"type_borne_id" = 23
You can recreate that in Python as well, in many different ways.
'"type_borne_id" = 23' # Note the single quote outside the query
'''"type_borne_id" = 23''' # Triple single quote (docstring)
The above two examples just show two ways. You can use escape characters and other ways as well. For more information, look into the Select help page on ESRI.
I realize this is an old post, but for anyone else that comes across it. If you don't know how your input file is (shapefile, geodatabase, or file geodatabase) there is a function that will append the field delimiters ([ or ") depending on the input featureclass.
See http://resources.arcgis.com/en/help/main/10.1/index.html#/AddFieldDelimiters/018v0000006p000000/
For further details.
Explore related questions
See similar questions with these tags.
whereClause = '"' + fieldName + '" = ' + "'" + fieldValue + "'"