微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将查询结果存储在 PSQL 中使用的变量中,并在其他查询的 where 条件中使用相同的变量

如何解决将查询结果存储在 PSQL 中使用的变量中,并在其他查询的 where 条件中使用相同的变量

我使用 Psql查询结果存储在变量中。我在其他查询中使用相同的变量,但出现语法错误

下面是代码

test1=$(psql -X -A -h $HOSTNAME -U $USERNAME -d $DATABASE -c "SELECT run_id from ( SELECT run.pystatusworktimestamp AS completion_time,run.pylabel AS campaign_name,run.pyid as campaign_RUN_ID,ih.run_id,run.pyoutputclassname AS batch_output_table,row_number() over (partition by ih.run_id) AS row_num FROM pegadata.interaction_history_view ih LEFT JOIN pegadata.pr_data_ih_dim_context ctxt ON ih.run_id = ctxt.pzid LEFT JOIN pegadata.mkt_work run ON run.dsmoutputconfiguration = ctxt.pycategory WHERE run.pystatuswork = 'Resolved-Completed' AND pxupdatedatetime > Now() - interval '24 hours' AND outcome = 'Proposed' ) campaigns where campaign_name = 'AoM_Reminder_Campaign_postpay2' and batch_output_table = 'Data-BatchOutPR727002'  and campaigns.row_num = 1 limit 10 ;")

psql -h $HOSTNAME -U $USERNAME -d $DATABASE -c "SELECT subscription_id,afm,proposition_name,tp_disc_amount,po_discount_perc_amount_1,po_discount_perc_amount_2,po_discount_perc_amount_3,po_discount_perc_amount_4 FROM pegadata.interaction_history_view where run_id = $test1 and (tp_disc_amount < 0 or tp_disc_amount > 100 or po_discount_perc_amount_1 < 0 " >>  output.txt

我收到以下错误

ERROR:  Syntax error at or near "$"
LINE 1: ... pegadata.interaction_history_view where run_id = $test1 and...

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。