我想知道如何在Postgres中的另一个RDBMS中运行以下代码。
UNIX脚本:
call_rdbms_sql.sh
内容:
CONNDETAILS<<EOF
select col1 from table1 where col1='&ValueofCol1';
EOF
我执行这个:
UNIXPROMPT$> ksh ./call_rdbms_sql.sh col1valuepassed
这将被传递到unix脚本中的sql脚本并提供结果。
我能够设置一个调用postgres sql的unix脚本。只要sql脚本没有提供任何提示,这部分工作正常。
但是,我想将值传递给“Where子句”。
-GV
你可以使用psql
的-v
选项传递变量
val=$1 #set the first argument to val
if [ -z $val ] #check if it is set, exit script if it's not
then
echo "Invalid input"
exit
fi
psql conndetails -v ValueofCol1=$val<<EOF
select col1 from table1 where col1=:'ValueofCol1'; --use : before quoting
--variable name
EOF