PostgreSQL-select..where:值可以为null时的语法

时间:2018-09-01 17:20:49

标签: postgresql plpy

我正在寻找格式化查询的正确方法,以便“ 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']
  );

它执行没有错误,但是没有给出正确的结果。

0 个答案:

没有答案