PostgreSQL - select..where: синтаксис, когда значение может быть нулевым - PullRequest
0 голосов
/ 01 сентября 2018

Я ищу правильный способ форматирования запроса, чтобы значение в предложении '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']
  );

Выполняется без ошибок, но не дает правильных результатов.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...