I tried to find the equivalent of Left fuction because it doesn't work in ArcGis. I found a post that suggested the word substring:

the query is:

WHERE (IAS.C_A)<>Left([C_A1],5)));

and I tried:

"('IAS.C_A')<>substring(['C_A1' from 1 for 5])"

in the function:

where_clause= "('IAS.C_A')<>substring(['C_A1' from 1 for 5]))";

but shows error in syntax.


"'IAS.C_A'<>'substring(C_A1, 1 ,5'")

For each part we add a single quote and a double one in the start and one in the end of the where clause.

  • Can you included the syntax error you received in your post?
    – whyzar
    Commented Oct 29, 2018 at 13:41
  • Parsing error SyntaxError: invalid syntax (line 1)
    – user51332
    Commented Oct 29, 2018 at 13:42
  • You are missing the end parenthesis. Also remove the ;. What exactly do you want to select?
    – Bera
    Commented Oct 29, 2018 at 14:16
  • I want to select where (IAS.C_A)<>Left([C_A1],5)
    – user51332
    Commented Oct 29, 2018 at 14:24

1 Answer 1


I know this answer was meant for city engine but the function should work the same.

substring takes 3 arguments, string, start, and the last one is either stop position or length.

the second answer here has an example of how to use it.

it is worth taking another look at the documentation, since the sql query examples it redirects to do use the LEFT function.

while LEFT did not work for me, testing with the natural earth countries layer i did use substring succefully, here is the example taking only the first letter from TYPE:

arcpy.Select_analysis(in_features="test", out_feature_class="C:/Projects/Natural_Earth/New File Geodatabase.gdb/test1", where_clause="substring(TYPE,1,2) = 'S'")
  • So is it accepting LEFT? how is the correct version of the query in question. Thanks
    – user51332
    Commented Oct 29, 2018 at 13:52
  • have you tried running it like the example in the sql reference? LEFT(C_A1,5)
    – Dror Bogin
    Commented Oct 29, 2018 at 13:57
  • Yes, it shows error all the time. I have tried so many combinations.
    – user51332
    Commented Oct 29, 2018 at 14:02
  • added a working example to my answer. @user51332
    – Dror Bogin
    Commented Oct 29, 2018 at 14:31
  • I found it finally. Thanks for the ideas. See the question to see the answer.
    – user51332
    Commented Oct 29, 2018 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.