how can I fix it list index out of range

0

I have a query and that query only throws me a record and when I optengo I ask you to throw me the value that is in the position [0]

for a in datos_estados:
    tabla_datos = [a["estado"], a["seccion"], 'Teorico']
    for vuelta in range(mes_inicio, 13):
        query = '''
                    SELECT NVL(TRIM(TO_CHAR(SUM(TOTAL),'999,999,999,999,999.00')),0) "teorico"
                    FROM CL_RP_COBRANZA_TNR_TEORICO
                    WHERE TO_CHAR(FECHA_VENCIMIENTO,'MM/RRRR')='{0}/{1}' AND
                          ESTADO='{2}' AND 
                          SECCION='{3}'
                    GROUP BY  ESTADO, 
                          SECCION
                    ORDER BY ESTADO, SECCION'''.format(vuelta, ano_inicio,a["estado"],a["seccion"])
        #print query
        datos_teorico = consulta_asociativa(query, conexion['cursor'])[0]
        tabla_datos.append(datos_teorico["teorico"])
        tabla_datos.append(" ")

In the query there is no record in the DB, for that reason it is why I can not find the position [0], but how can I avoid not getting an error?

    
asked by Jonathan Garcia 08.08.2018 в 22:12
source

1 answer

0

I'm assuming that the query_asiosiada function returns a queryset

    datos_teorico = consulta_asociativa(query, conexion['cursor'])
    if datos_teoricos.exists():
        tabla_datos.append(datos_teorico[0]["teorico"])
        tabla_datos.append(" ")
    
answered by 10.08.2018 в 15:40