0

I am looking for the correct way to format a query so that a value in the 'where' clause can be null.

I tried this:

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']
  );

It executes without error, but does not give the correct results.

Crashmeister
  • 375
  • 1
  • 14

0 Answers0