Alternative way to list all part tables that have existing entries/tuples

75 Views Asked by At

I have one single master Subject table which have several part tables. One convenient thing about Table.delete() is that is displays a prompt with all existing entries that were created under that Subject. Aside from delete() is there an alternative way to print what part table entries were created under a single Subject entry?

Thank you

2

There are 2 best solutions below

0
On BEST ANSWER

It's a slow process, but I think I would do the following to see where entries were:

(subject.Subject & 'subject="<NAME>"').descendants(as_objects=True)

Not sure if you'd be better off with children (1 level down) or descendants (all the way down). delete gives the full set of descendants, using table.delete_quick(get_count=True).

EDIT: To just get the counts, you might want:

[print(i.table_name,len(i)) for i in (subject.Subject & 'subject="<NAME>"').descendants(as_objects=True)]
0
On

To get the entry count of all the part tables restricted by some restriction (e.g. subject_name), you can do something like this:

restriction = {'subject_name': 'my_star_subject'}

for part_table in Subject.parts(as_objects=True):
    part_table_query = part_table & restriction
    print(f'{part_table.table_name}: len(part_table_query)')