红移-除以零行为

时间:2018-12-26 09:37:11

标签: python-3.x amazon-redshift psycopg2

我正在尝试使用Python和psycopg2查询我的Redshift集群。 请参考以下详细信息:

for i in x:
    function_name(p1,p2)

def function_name(parameter_one,parameter_two):
    try:
        //Create Query
       //Create query dynamically


        //Run query here
        SELECT (SELECT SUM(value)
        FROM schemaName.tableName
        WHERE primary_key = 12532
        AND   TO_CHAR(tr_datetime,'YYYYMMDDHH24MI') > '201709162130'
        AND   TO_CHAR(tr_datetime,'YYYYMMDDHH24MI') <= '201709162145')/(SELECT SUM(value)
                                                                        FROM schemaName.tableName
                                                                        WHERE primary_key = = 12542
                                                                        AND   TO_CHAR(tr_datetime,'YYYYMMDDHH24MI') > '201709162130'
                                                                        AND   TO_CHAR(tr_datetime,'YYYYMMDDHH24MI') <= '201709162145');

    except Exception as exception:
        print("Error-----------------------------------")
        error = 'Error on line {}'.format(sys.exc_info()[-1].tb_lineno), type(exception).__name__, exception
        message = str(error)
        print("Error message " + str(exception))
        print("EXCEPTION OCCURRED" + message)

我面临的问题是每当遇到Divide by zero我的程序停止执行时。我收到以下消息。请参考下面的堆栈跟踪:

2018-12-21 13:50:36 -- EXCEPTION OCCURRED in module x for 12532
2018-12-21 13:50:36 -- EXCEPTION OCCURRED in module x for 12532
13:50:36
2018-12-21 13:50:36 -- ('Error on line 1062', 'QueryCanceledError', QueryCanceledError('Divide by zero\n',))
2018-12-21 13:50:36 -- ('Error on line 1062', 'QueryCanceledError', QueryCanceledError('Divide by zero\n',))
13:50:36
2018-12-21 13:50:36 -- EXCEPTION OCCURRED in module x for primary key 12532
2018-12-21 13:50:36 -- EXCEPTION OCCURRED in module x for primary key 12532
13:50:36
2018-12-21 13:50:36 -- ('Error on line 1001', 'InternalError', InternalError('current transaction is aborted, commands ignored until end of transaction block\n',))
2018-12-21 13:50:36 -- ('Error on line 1001', 'InternalError', InternalError('current transaction is aborted, commands ignored until end of transaction block\n',))
13:50:36
2018-12-21 13:50:36 -- EXCEPTION OCCURRED in module x for 12532
2018-12-21 13:50:36 -- EXCEPTION OCCURRED in module x for 12532
13:50:36
2018-12-21 13:50:36 -- ('Error on line 1001', 'InternalError', InternalError('current transaction is aborted, commands ignored until end of transaction block\n',))
2018-12-21 13:50:36 -- ('Error on line 1001', 'InternalError', InternalError('current transaction is aborted, commands ignored until end of transaction block\n',))

我的问题是为什么我的连接关闭? 为什么得到current transaction is aborted, commands ignored until end of transaction block,我希望程序继续进行其他迭代,因为我的代码封装在try / catch块中。

如果有人可以帮助我了解Redshift和Python的根本原因和背景行为,那将是很好的。

0 个答案:

没有答案