PostgreSQL python触发得到奇怪的错误

时间:2018-04-02 18:49:53

标签: python-3.x postgresql database-trigger

PostgreSQL V10。 Python V3.6。代码在' INSTER INSERT'触发。

首先是错误:

if not isinstance(vector, list):
  print("Wrong input type for index {}: {}".format(i, vector))

似乎直截了当,但我找不到任何名为“' ts”的东西。我查看了可能由插入执行的所有相关代码。

这是该功能的相关部分。错误发生在' sellRslt ='行:

ERROR: spiexceptions.ExternalRoutineException: NameError: name 'ts' is not defined
  Where: Traceback (most recent call last):
  PL/Python function "trade_buy_after", line 30, in <module>
cashRslt[0]['symbol'], cashRslt[0]['price'], 0.00, tbRow['amount'], const['SW_OUT'], note]);
PL/Python function "trade_buy_after"

这是日志输出:

  tbRow = TD['new'];

  _logger.debug(tbRow);

  if tbRow['source_revenue_id'] == None:
    _logger.debug("tb after: rev == None");
    note = "Sweep-Out for purchase of " + str(tbRow['qty']) + " " + tbRow['symbol'] + " @ " + "${:<9.2f}".format(tbRow['price']);
    _logger.debug(note);
    cashRslt = plpy.execute(GD['get_cashSymbolAndCurrentPrice'], [tbRow['account_name']]);
    _logger.debug("got cash data: " + cashRslt[0]['symbol'] + " ${:<9.2f}".format(cashRslt[0]['price']));

    sellRslt = plpy.execute(GD['insert_trade_sell'], [tbRow['account_name'], tbRow['settlement_date'], tbRow['settlement_date'], tbRow['amount'] / cashRslt[0]['price'],
    cashRslt[0]['symbol'], cashRslt[0]['price'], 0.00, tbRow['amount'], const['SW_OUT'], note]);

    _logger.debug("tb done");

&#39; insert_trade_sell&#39;中的SQL从我的IDE执行正常。这是:

2018-04-02 14:27:11,933 [DEBUG   ] plpy.tba : {'sys_upd_user': 'dba', 'note': 'Buy', 'sys_updated_ts': '2018-04-02  14:27:11.930796-04', 'sys_created_ts': '2018-04-02 14:27:11.930445-04', 'symbol': 'BLV',
'adjusted_price': Decimal('88.6590'), 'price': Decimal('88.5600'), 'source_revenue_id': None, 'qty_left': Decimal('100.0000'), 'settlement_date': '2016-01-30', 'amount': Decimal('8860.95'),
'qty': Decimal('100.0000'), 'account_name': 'VG Savings', 'lot': 4, 'fees': Decimal('4.95'), 'source_sell_id': None, 'trade_date': '2016-01-28'}
2018-04-02 14:27:11,933 [DEBUG   ] plpy.tba : tb after: rev == None
2018-04-02 14:27:11,933 [DEBUG   ] plpy.tba : Sweep-Out for purchase of 100.0000 BLV @ $88.56    
2018-04-02 14:27:11,934 [DEBUG   ] plpy.tba : got cash data: VMFXX $1.00     

0 个答案:

没有答案