我正在寻找格式化查询的正确方法,以便“where”子句中的值可以为空。
我试过这个:
getTxCount = plpy.prepare("""
select count(*) from trade_tx_tbl
where account_name = $1
and trade_date = $2
and settlement_date = $3
and action = $4
and income_source = $5
and coalesce(qty, 0) = coalesce($6, 0)
and coalesce(symbol, '_') = coalesce($7, '_')
and coalesce(price, 0) = coalesce($8, 0)
and fees = $9
and amount = $10
and tx_source = $11
and coalesce(user_note, '_') = coalesce($12, '_')
""",
['text', 'date', 'date', 'text', 'text', 'numeric(13,6)', 'text', 'numeric(13,4)', 'numeric(13,2)', 'numeric(13,2)', 'text', 'text']
);
它执行没有错误,但没有给出正确的结果。