我在Rails(postgres db)中有此准备好的语句:
conn = ActiveRecord::Base.connection.raw_connection
conn.prepare('query_fetch_dest_values',
"SELECT q.entity AS source_entity,
q.financial_institution AS source_financial_institution,
q.account_number AS source_account_number,
a2.entity AS destination_entity,
a2.financial_institution AS destination_financial_institution,
a2.account_number AS destination_account_number
FROM
(SELECT *
FROM forecast_entry_and_cash_positions
INNER JOIN accounts a ON forecast_entry_and_cash_positions.source_account_id = a.account_number
WHERE (input_type IN ($1) AND
a.financial_institution IN ($2) AND
forecast_entry_and_cash_positions.source_account_id IN ($3))
)q LEFT JOIN accounts a2 ON q.dest_account_id = a2.account_number")
search_destination_values =
conn.exec_prepared('query_fetch_dest_values',
[decode_input_type(params[:search_input_type]),
params[:search_source_financial_institution],
params[:search_source_account_number]
])
puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
puts search_destination_values.inspect
inspect
中,这就是在控制台上打印的内容:#<PG::Result:0x00007f9d32c528b8 status=PGRES_TUPLES_OK ntuples=0 nfields=6 cmd_tuples=0>
我从这个博客了解到-https://blog.kiprosh.com/understanding-pg-result-object/上述输出中的nTuples=0
和cmd_tuples=0
表示SQL返回的记录数为0。
我在pgadmin中的查询返回3条记录-为什么我在这里没有得到任何输出?
=
(等于)条件时,如何传递过滤器的动态值。但是在我的情况下,我有3个IN
过滤器。该文档没有显示为IN
子句传递动态过滤器的示例。在上面的代码片段中,为我的3个IN
子句传递动态过滤器的方式正确吗? (同样,由于我的查询没有在控制台上打印,所以我无法验证我的过滤器是否正确添加到SQL中。)>
我在Rails(postgres db)中有此准备好的语句:conn = ActiveRecord :: Base.connection.raw_connection conn.prepare('query_fetch_dest_values',“ SELECT q.entity AS source_entity,...