arcpy.GetCount_management not working with queried tables

554
2
09-17-2013 01:36 PM
JuanOrozco
Occasional Contributor
Is anyone else having trouble with arcpy.GetCount_management using a queried table?

I have a table in my TOC (not a feature class) and then I apply a query as:

[INDENT]myTable.definitionQuery = "some query"[/INDENT]

Query works fine, but when I try getting the count of records in table as:

[INDENT]count = int(arcpy.GetCount_management(myTable).getOutput(0))[/INDENT]

The result is the total number of rows before the query. If I do the same thing with a feature class it works fine. I'm running this in a simple stand alone script.

Just curious if anyone else had his problem. I worked around this by looping a cursor and counting the rows, so no big deal.
Tags (2)
0 Kudos
2 Replies
MathewCoyle
Frequent Contributor
I too get this behaviour. I get around it by creating the table view in this manner.

arcpy.MakeTableView_management(data, table, 'OBJECTID < 100')


As opposed to this, if this is how you are doing it.

table = arcpy.MakeTableView_management(data)
table.definitionQuery = 'OBJECTID < 100'
0 Kudos
JuanOrozco
Occasional Contributor
I too get this behaviour. I get around it by creating the table view in this manner.

arcpy.MakeTableView_management(data, table, 'OBJECTID < 100')


As opposed to this, if this is how you are doing it.

table = arcpy.MakeTableView_management(data)
table.definitionQuery = 'OBJECTID < 100'


You're right, I was getting my table like that. I will start doing it as you do it. Thank you so much.
0 Kudos