Blender and requests PostgreSql
Syntactically something like this should work (I striped the DB code):

import bpy

mat_M= bpy.data.materials.get('2015')
year='2014'
for obj in bpy.data.objects:
    c = None
    print(obj)
    if obj.type=='MESH':
        c=obj
    if c == None:
        continue                      
    c.active_material=mat_M
    c.hide=False          
    if c.name in bpy.data.groups["Child"].objects:
        parent=c.parent
        recentParent = [[2014],[2015]]
        for recent in recentParent:                      
            if recent[0]!=None:
                yearParent=str(recent)
                if yearParent&gt;=year:
                    c.hide=True


for recent in recentParent iterates over the result of the db query, try your exact statement in a UI for your SQL server. If it doesn't return any data you need to fix that first. DB connections are better ask on stackoverflow. Note that there is a space in id_ works